How to use Prettify JSON

  1. Paste your JSON into the Input JSON editor, or click Select files to load it from a file.
  2. Under Indentation, select Use Spaces and type the number of spaces per level (2 by default), or select Use Tabs.
  3. Check the formatted output in the Prettified JSON panel. It is regenerated whenever you change the input or the indentation, as long as the input is valid JSON.
  4. Click Copy to clipboard to copy the result, or Download to save it as a .json file.

Examples

Array with four-space indentation

Input: [ 1, 2,3 ] spread unevenly over several lines, with Use Spaces set to 4. Output: the array with 1, 2 and 3 each on its own line, indented by four spaces.

Minified object with two spaces

Input: {"names":["jack","john","alex"],"hobbies":{"jack":["programming","rock climbing"]}}. With Use Spaces set to 2, every key and array item goes on its own line, with two spaces added for each nesting level.

Tab indentation

Input: an object with extra spaces around keys and colons, such as { "name": "The Name of the Wind", "published" : 2007 }. With Use Tabs selected, the extra spaces are removed and each key goes on its own line, indented by one tab per nesting level.

Good to know

  • The input is parsed with JavaScript's JSON.parse. If it is not valid JSON, an Invalid JSON string error message appears and the output panel is not updated.
  • The space count is passed to JSON.stringify, which uses at most 10 spaces per level. A count of 0 or an empty field gives compact output with no line breaks.
  • Values are re-serialized by JavaScript. Integers larger than 9007199254740991 can lose precision, numbers are rewritten in JavaScript form (1.0 becomes 1, 1e2 becomes 100), and if a key appears twice in the same object only its last value is kept.
  • The input and output editors use the Monaco code editor. The page downloads it from cdn.jsdelivr.net when an editor loads.

Frequently asked questions

Can it repair invalid JSON such as trailing commas?

No. It only re-indents text that JSON.parse accepts. Trailing commas, unquoted property names and comments trigger the Invalid JSON string error. To see the parser's exact message, use the Validate JSON tool.

Can I format JSON Lines (NDJSON)?

Not with this tool. It parses the whole input as one JSON document, so several JSON values on separate lines fail to parse. The Minify JSON and Validate JSON tools accept JSON Lines input.

More JSON Tools