Docs > API > JSON
JSON (JavaScript Object Notation) is a simple standard for representing JavaScript data structures as strings.
This class contains methods to convert JSON strings into JavaScript objects and back again.
For example:
For example:
This class contains methods to convert JSON strings into JavaScript objects and back again.
For example:
str = '{"one":"1", "two":"2", "three":"3", "four":"4"}';
obj = JSON.parse(str);
// => The object "obj" now has four properties ("one", "two", etc.)
out.writeln(obj.two);
// => 2
strAgain = JSON.stringify(obj);
out.writeln(strAgain);
// => {"one":"1","two":"2","three":"3","four":"4"}
Note that you should not use these JSON methods to serialize E4X objects. You should use the toXMLString() method instead.For example:
e4x = <message>
<greeting>Hello world!</greeting>
<farewell>Goodbye world!</farewell>
</message>;
str = e4x.toXMLString();
// We need to convert XML characters such as '<'
// into their corresponding XML entities (e.g. <),
// in order for them to render properly in the web
// console. Hence, we use kit.xmlEscape()
out.writeln(kit.xmlEscape(str));
e4xAgain = new XML(str);
out.writeln(e4xAgain.greeting);
// => Hello world!
For more detailed information on the following methods, please see http://www.json.org/json2.js
| Methods | |
|---|---|
| parse(string) | Deserialize a string into a JavaScript object. |
| stringify(object) | Serialize a JavaScript object into a string. |



