Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

json
stringify
parse
javascript
js

What is JSON.stringify in JavaScript?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

JavaScript Object Notation (JSON) is a light-weight data storage format for storing and transmitting data. It is stored in the form of key-value pairs.

What sets JSON apart from other data formats is its human-readable and self-describing properties.

svg viewer
Data in JSON format

What is JSON.stringify?

As compared to JSON, which is a data storage and transmission notation, JSON.stringify is a method in JavaScript which, given a JSON object as an argument, returns JSON text in string format.


What does the JSON.stringify method do?

As described above, a big reason for converting data to JSON format is so that it can be transmitted. But to send and receive data to a web server, the data has to be in string format. That’s where the JSON.stringify method comes into play. It converts a JSON object to JSON text stored in a string, which can then be transmitted to the web server.


Example

Let’s see how we can use the JSON.stringify method to convert a string, data, into a JSON object.

var json = {"platform": "Educative",
"established": 2015};
data = JSON.stringify(json);
console.log(typeof data); // expected output: string
console.log(data); // expected output: json data in string format

RELATED TAGS

json
stringify
parse
javascript
js
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring