What is JSON.stringify()?

Answered

What is JSON.stringify()?

Ninja Asked on 19th September 2018 in JSON.
Add Comment
1 Answer(s)
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}”

Ninja Answered on 19th September 2018.
Add Comment