Advertise with us

JSON.stringify()

What is JSON.stringify().

Last updated:7/3/2018 4:52:01 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

JSON.stringify() :

Exchange data from a web server in JSON is common use. When we sending data to a web server,the data has to be a string. Convert a JS object into a string with JSON.stringify(). 

Stringify a JavaScript Object: 

var obj = { "name":"Prakash", "age":19, "city":"Allahabad"};

var myJSON = JSON.stringify(obj);

Example:

var obj = { "name":"Prakash", "age":19, "city":"Allahabad"};

var myJSON = JSON.stringify(obj);
document.getElementById("Mindstick").innerHTML = myJSON;


Stringify a JavaScript Array :

var arr = [ "Prakash", "Nidhi", "Verma", "mindstick" ]; 
var myJSON = JSON.stringify(arr);

Ex: 

var arr = [ "Prakash", "Nidhi", "Verma", "mindstick" ];

var myJSON = JSON.stringify(arr);
document.getElementById("Mindstick").innerHTML = myJSON;

Answer