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)

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

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.