Home >Web Front-end >JS Tutorial >How does JavaScript provide native JSON parsing and serialization?
Browser-Native JSON Parsing and Serialization
The window.JSON object provides native JSON support in modern browsers, including Internet Explorer 8 , Firefox 3.1 , Safari 4 , and Chrome 3 . This object exposes two methods:
JSON.parse(str)
Parses the JSON string str and returns an object representing the decoded data.
JSON.stringify(obj)
Returns a JSON representation of the JavaScript object obj.
Examples
<code class="js">// Parse JSON string const data = JSON.parse('{"name": "John", "age": 30}'); // Serialize object to JSON string const json = JSON.stringify({ name: "Jane", age: 35 });</code>
Additional Information
For more detailed documentation, refer to the MDN article:
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)
The above is the detailed content of How does JavaScript provide native JSON parsing and serialization?. For more information, please follow other related articles on the PHP Chinese website!