Pretty print json string in JavaScript

Pretty print a JSON string using JavaScript into an easy-to-read format with indentation and whitespace.

var input = '{"null":null,"true":true,"false":false,"integer":1,"float":3.14,"string":"string"}';
var output = JSON.stringify(JSON.parse(input), null, 2);
  "null": null,
  "true": true,
  "false": false,
  "integer": 1,
  "float": 3.14,
  "string": "string"
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment