Encountered this article today:
It discusses how to parse and serialize JSON, and references this article by John Resig written in May of 2009, as a reference for using json2.js. While the information in the article is (arguably) partially relevant, it's extremely dated.
I'd like to propose the following edits to it. Are these suitable edits for SO, and is this sufficient justification to edit the current answer?
- Reposition the details about native implementation to the top of the answer, moving the link to json2.js below
- Remove the quote and reference to John Resig's article.
E.g.:
For modern browsers:
To convert an object to a JSON string, use JSON.stringify
:
var json_text = JSON.stringify(your_object, null, 2);
To convert a string to JSON object, use JSON.parse
:
var your_object = JSON.parse(json_text);
For legacy browsers:
While Newer browsers support the JSON object natively, older ones do not. One workaround is to use json2.js, which gracefully falls back eval()
on older browsers, while another is to implement jQuery.parseJSON.