JSON.stringify()
has more than one argument:
- value – the value one wants to convert to a string
- replacer – an array or a function to filter fields
- space – the number of spaces (or a string) to use for indentation
var person = {"name":"Jim Cowart","location":{"city":{"name":"Chattanooga","population":167674},"state":{"name":"Tennessee","abbreviation":"TN","population":6403000}},"company":"appendTo"};
JSON.stringify(person, ["name", "company"], 4);
/* produces:
"{
"name": "Jim Cowart",
"company": "appendTo"
}"
*/
What You Might Not Know About JSON.stringify() →
(via @LeaVerou)
Leave a comment