JSON Formatter

Please type or paste your JSON data below and click the button.


This tool uses the native JSON object and its methods: JSON.parse() and JSON.stringify().

JSON.parse(text) parses a parameter string text as JSON, and returns the object corresponding to the JSON text. It throws a SyntaxError exception if the string is not valid JSON.

try {
    JSON.parse('{}'); // {}
    JSON.parse('[1, 2, "false"]'); // [1, 2, "false"]
    JSON.parse('{"id": 123, "name": "Alice"}');
} catch (e) {
    alert("Parsing error:", e); 
}

JSON.stringify(value) coverts a JavaScript object value and returns a JSON string. JSON.stringify(value, null, space) uses the space argument to control spacing in the final string. It could be a number or a string, and successive levels in the stringification will each be indented by the number of spaces or the string.

var text = JSON.stringify({id: 123, name: "Alice"}, null, '  ');
{
  "id": 123,
  "name": "Alice"
}

Related Posts

Comments

comments