json.stringify format code example
Example 1: json.stringify pretty
var str = JSON.stringify(obj, null, 2); // spacing level = 2
Example 2: Javascript object to JSON string
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Example 3: javascript json stringify indented
JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, 4); // Indented 4 spaces
JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, "\t"); // Indented with tab