JavaScript JSON Complete Reference
JavaScript JSON (JavaScript Object Notation) is a lightweight format for storing and exchanging data. It is easy to read, write, and parse. JSON is based on key-value pairs and arrays.
let data = '{"name":"Raj","age":25}';
let obj = JSON.parse(data); // Convert JSON string to object
console.log(obj.name);
Output
Raj
The complete list of JavaScript JSON methods are listed below:
JavaScript JSON Methods
Method | Description |
---|---|
parse() | JSON format and return a JavaScript object. |
stringify() | It creates a JSON string out of it. |
JSON Properties in JavaScript
Methods | Description |
---|---|
Returns an array of keys from a JSON object. | |
Returns an array of values from a JSON object. | |
Returns an array of key-value pairs from a JSON object. |
JSON Operations
Operation | Description |
---|---|
Convert JSON string to JavaScript object. | |
Convert JavaScript object/array into JSON string. | |
Check if a string is a valid JSON using try-catch block. | |
Convert JavaScript objects, arrays, or values to JSON strings. | |
Handle errors gracefully when working with JSON (e.g., invalid format). | |
Format JSON output for better readability. |