Home  >  Article  >  Web Front-end  >  How does JavaScript provide native JSON parsing and serialization?

How does JavaScript provide native JSON parsing and serialization?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-20 15:13:29677browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn