This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

JSON

Summary

JSON is a native API for parsing and serialising information to the JSON format.

JSON contains two methods: parse for parsing JSON strings, and stringify for converting a JavaScript object into JSON.

Properties

No properties.

Methods

parse
Parse a JSON string to a JavaScript object.
stringify
Export a JavaScript object to a JSON string.

Events

No events.

Examples

Convert a JavaScript object to a string.

var js_object = {
    type: "This is a Javascript Object."
};

var json_string = JSON.stringify(js_object);

Parse a JSON string to a JavaScript object.

var json_string = '{type:"This is a JSON Object."}';
var js_object = JSON.parse(json_string);
alert(js_object.type);

Notes

Browsers without JSON support can be polyfilled using third party JavaScript libraries.

Related specifications

JSON-LD 1.0
W3C Recommendation