using JSON.parse in a script

Jan 4, 2014 at 5:14 PM
Hi,
I am trying to parse a json string as below (please let me know what i am doing wrong here)
engine.ExecuteCommand("JSON.parse('{\"x\":1}');");
I get the following exception:
Microsoft.ClearScript.ScriptEngineException: 'JSON' is undefined
Result StackTrace:
at Microsoft.ClearScript.ScriptEngine.ThrowScriptError(IScriptEngineException scriptError)
at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass14.<ScriptInvoke>b__13()
at Microsoft.ClearScript.ScriptEngine.ScriptInvoke(Action action)
at Microsoft.ClearScript.Windows.WindowsScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard)
at Microsoft.ClearScript.ScriptEngine.ExecuteCommand(String command)
Coordinator
Jan 4, 2014 at 6:40 PM
Hello!

Unfortunately JScriptEngine currently does not support the JSON object. It is compatible with JScript 5.7, but the JSON object was added in JScript 5.8. We're going to fix this in the next release.

BTW, V8ScriptEngine supports JSON.

Thank you for reporting this issue!
Coordinator
Jan 9, 2014 at 10:42 PM
Hi again!

ClearScript 5.3.11 will support JScript 5.8 language enhancements, including the JSON object, but you'll have to enable them explicitly via a new flag. That's because these enhancements come with their own bugs and backward compatibility issues - part of the reason why websites back in the IE8 days had to opt-in to "Standards Mode" :)

Cheers!
Feb 12, 2014 at 7:56 AM
Hi,
Thanks ! What is the flag I need to enable to use this feature ?
Coordinator
Feb 12, 2014 at 12:24 PM
Hello!

The new flag is WindowsScriptEngineFlags.EnableStandardsMode. It enables the JSON object as well as other, less prominent standards compliance improvements.

Good luck!