JavaScripture
Contribute via GitHub Feedback

JSON : Object

Contains methods for encoding and decoding JSON strings.

JSON Methods

parse 2 variants
parse(str : String) : Object

Parses the specified string of JSON and converts it to an Object.

Example:

Run

Results:

 

parse(str : String, reviver : Function) : Object
reviver(key : String, value : String) : Object

Parses the specified string of JSON and converts it to an Object. reviver will be called for each parsed key/value pair and the function's return value is used in place of the value.

Example:

Run

Results:

 

stringify 3 variants
stringify(value : Object) : String

Converts value to a JSON string. If value has a toJSON() method on it, the return value of that method will be used.

Example:

Run

Results:

 

stringify(value : Object, keyNames : Array<String>, [indent : String]) : String

Converts value to a JSON string. If keyNames is not null, only key/value pairs where the key is in keyNames will be in the JSON string. If indent is specified, each key/value pair will be on a new line with the indent string before the key.

Example:

Run

Results:

 

stringify(value : Object, replacer : Function, [indent : String]) : String
replacer(key : String, value : Object) : String

Converts value to a JSON string. The replacer function is called for each key/value pair and the return value is used as the value in the final string. If indent is specified, each key/value pair will be on a new line with the indent string before the key.

Example:

Run

Results: