JSON

The JSON object is new to ES5. It's not a constructor (similarly to Math) and has only two methods: parse() and stringify(). For ES3 browsers that don't support JSON natively, you can use the "shim" from http://json.org.

JSON stands for JavaScript Object Notation. It's a lightweight data interchange format. It's a subset of JavaScript that only supports primitives, object literals, and array literals.

Members of the JSON object

Method

Description

parse(text, callback)

Takes a JSON-encoded string and returns an object:

> var data = '{"hello": 1, "hi": [1, 2, 3]}';
> var o = JSON.parse(data);
> o.hello;
1
> o.hi;
[1, 2, 3]

The optional callback lets you provide your own function that can inspect and modify the result. The callback takes ...

Get Object-Oriented JavaScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.