JSON.stringify()’s arguments

JSON.stringify() has more than one argument:

  1. value – the value one wants to convert to a string
  2. replacer – an array or a function to filter fields
  3. 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)

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.