Name

JSON — JSON parsing and stringification

Availability

ECMAScript 5

Description

JSON is a simple object that serves as the namespace for the global ECMAScript 5 functions JSON.parse() and JSON.stringify(). JSON is not a constructor. Prior to ECMAScript 5, compatible JSON parsing and serialization functions are available from http://json.org/json2.js.

“JSON” stands for JavaScript Object Notation. JSON is a data serialization format based on JavaScript literals, and can represent the null value, the boolean values true and false, floating-point numbers (using JavaScript numeric literals), strings (using JavaScript string literals), arrays of values (using JavaScript array literal syntax) and string to value mappings (using JavaScript object literal syntax). The primitive value undefined as well as the numbers NaN and Infinity are not representable in JSON. JavaScript functions, Dates, RegExps and Errors are not supported either.

Example

// Make a deep copy of any object or array that can be JSON-serialized
function deepcopy(o) { return JSON.parse(JSON.stringify(o)); }

Get JavaScript: The Definitive Guide, 6th 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.