JavaScript JSON
Last Updated : 24 Jan 2026
The JavaScript JSON is an acronym of JavaScript Object Notation which is one of the most important topics in modern web development. It provides a format for storing and transporting data between a browser and a server. It is a light-weight human-readable collection of data that can be accessed in a logical manner. If you are learning JavaScript or working with web APIs, you must understand JSON. Even though it is based on JavaScript syntax, JSON is just a text, but it is written in a format that looks like JavaScript objects.
JSON Syntax
1. While working with a .jsonfile, the syntax will be like:
2. While working with a JSON object in .jsor .htmlfile, the syntax will be like:
JavaScript JSON Methods
Let's see the list of JavaScript JSON methods with their description.
| Methods | Description | Input | Output | Use Cases | Optional Parameters | Example |
|---|---|---|---|---|---|---|
| JSON.parse() | This method takes a JSON string and transforms it into a JavaScript object. | JSON string | JavaScript object, array, value | Read API responses, load saved JSON from file or localStorage | - reviver: function to transform/modify values while parsing | JSON.parse('{"name": "Karan"}') |
| JSON.stringify() | This method converts a JavaScript value (JSON object) to a JSON string representation. | JavaScript object, array, number, etc. | JSON string | Send data to a server, store in localStorage, or log as a string | - replacer: function or array to filter / modify properties - space: number of spaces for formatting | JSON.stringify ( {name: "Karan"} ) à ' {"name": "Karan"}' |
JavaScript JSON Examples
Let's see an example to convert a string in JSON format using the parse() and stringify() methods.
Example
Output:
Convert string in JSON format using parse() method
XYZ
Convert string in JSON format using stringify() method
{"Name":"Krishna","Email":"XYZ","CN":12345}
Why use JSON in JavaScript?
1. To exchange data between Client and Server
JSON is the standard format for sending and receiving data in web applications. When your browser talks to a server (via an API), the data is often sent in JSON.
2. To Store Data Locally
You can store data in the browser using localStorage or sessionStorage, but they only accept strings. You can easily store and retrieve entire objects or arrays with JSON.
3. To convert between Objects and Strings
JavaScript's JSON.stringify() and JSON.parse() make it simple to convert data to/from strings which is useful when sending data over a network or saving it to storage.
4. It is easy to read and write
JSON syntax is simple, clean and looks like JavaScript object syntax. It is easy for humans to read and easy for machines to parse.
5. Widely Supported Format
JSON is language-independent, which means it can be used not just in JavaScript, but also in Python, Java, PHP, etc. This makes it ideal for sharing data between systems written in different languages.
6. Used in Configuration Files
JSON is used in many tools and platforms to store configuration data. Example: package.json in Node.js projects.
7. Efficient and Lightweight
JSON is smaller in size in contrast to other formats like XML which makes it faster to transfer and load.
Points to remember
- JSON is a lightweight, text-based format for storing and exchanging data.
- It is motivated by JavaScript object syntax but used as a string format.
- Commonly used in web APIs, AJAX and data storage like localStorage.
- Use JSON.stringify() to convert a JavaScript object to a JSON string.
- Use JSON.parse() to convert a JSON string back to a JavaScript object.
- It does not support functions, undefined, symbols or comments.
- All keys and string values must be in double quotes (" ").
- JSON is language-independent and used across many programming languages.
Conclusion
JSON (JavaScript Object Notation) is a simple, structured and widely used format for storing and exchanging data in JavaScript applications. It enables seamless communication between clients and servers, especially in web APIs. With just two core methods i.e., JSON.stringify() and JSON.parse(), developers can easily convert data between JavaScript objects and JSON strings. It is lightweight and language-independent nature makes JSON an essential tool for modern web development, helping developers build dynamic, efficient and data-driven applications.
Next TopicJavaScript JSON.parse() method