Nearby lessons

22 of 22

JavaScript: JSON.parse() & JSON.stringify()

๐Ÿ“Œ What are JSON Methods?

JSON.stringify() converts JavaScript objects/arrays into a JSON string, while JSON.parse() converts JSON strings back into JavaScript objects.

1๏ธโƒฃ Convert Object to JSON String

JSON.stringify() is used to convert a JavaScript object to a JSON string.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

2๏ธโƒฃ Convert JSON String to Object

JSON.parse() is used to convert a JSON string back into a JavaScript object.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

3๏ธโƒฃ Nested Object Conversion

Nested objects are also supported when using JSON.stringify() or JSON.parse().

Code Example
PREVIEW READY
Loading Editor...
Live Preview

4๏ธโƒฃ Convert Array to JSON and Back

You can also use JSON methods with arrays.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

5๏ธโƒฃ Use Replacer Parameter with JSON.stringify()

You can specify which properties to include by using the replacer array in JSON.stringify().

Code Example
PREVIEW READY
Loading Editor...
Live Preview

6๏ธโƒฃ Beautify JSON Output with Indentation

JSON.stringify() can format output using the third parameter (space).

Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿง  Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Course Complete!