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.
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.
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.
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: stringconsole.log(data); // expected output: json data in string format
Free Resources