json

< apis
Jump to: navigation, search

JSON

This article is Ready to Use.

W3C Recommendation

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

API Name Summary
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.

JavaScript

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

var json_string = JSON.stringify(js_object);

Parse a JSON string to a JavaScript object.

JavaScript

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

Specification Status Related Changes
JSON-LD 1.0 W3C Recommendation