json

Jump to: navigation, search

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

No methods.

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.


Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 1
3.5
8
10.5
4

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic Support 2.1
7
18
15
?
12
5
4