What is JSON.stringify()?
Answered
What is JSON.stringify()?
Best answer
JSON.stringify() converts a primitive value, object or array to a JSON-formatted string. A JSON stringify() works in the opposite direction of JSON.parse(), converting JavaScript data structures into JSON text.
var obj = JSON.stringify([1, “false”, false]);
//Produces “[1, “false”, false]”
var jsObject = {firstname: “James”, lastname: “Jackson”, age: 25};
var jsonObj = JSON.stringify(jsObject);
//Produces “{“firstname”:”James”, “lastname”:”Jackson”, “age”: 25}”