Skip to content

What is the Difference Between JSON.stringify and JSON.parse

The JSON object has two methods to deal with JSON-formatted content: parse() and stringify(). Let’s see what each of them does and what the major differences are between these two methods.

JSON.parse()

The JSON.parse() method takes a JSON string and transforms it into a JavaScript object. Parsing means to divide into grammatical parts and identify the parts and their relations to each other. After parsing the string from web server, it becomes a JavaScript object and then you can access the data. Here is an example of JSON.parse():

Javascript JSON parse method

Output appears here after Run.

JSON.stringify()

The JSON.stringify() method takes two additional arguments, where the first one is a replacer function and the second one is a String or Number value to use as a space in the returned string:

Javascript JSON stringify method

Output appears here after Run.

As the web server uses strings, the data being send to the server has to be a string. So the JSON.stringify() method is designed to convert a JavaScript object into a string to send it to the server.

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.