Developer Tools

JSON Formatter

JSON formatter and validator that re-indents JSON with 2 spaces, 4 spaces or a tab, minifies it, and shows the data as a collapsible tree.

Input JSON
Output

    

This JSON formatter re-indents minified or messy JSON with 2 spaces, 4 spaces or a tab, checks that it is valid, and can minify it back onto one line. The JSON Explorer under the output shows the same data as a tree you can fold open and shut. Everything runs in your browser with its built-in JSON parser, so the data is not uploaded.

How to use the JSON formatter

  1. Paste your JSON into the Input JSON box, or press Try Example to load a sample user record.
  2. Pick 2 spaces, 4 spaces or Tab from the Indent menu.
  3. Wait half a second. When the input starts with { or [ and ends with the matching bracket, the tool formats it on its own. You can also click Format / Prettify or press Ctrl+Enter (Cmd+Enter on a Mac).
  4. Click Minify to put the data on one line, or Validate to check it without changing the output. Validate also reports the root type, such as object or array.
  5. Press Copy above the Output box. The line under the input compares the input and output size in characters and bytes.

Example: formatting an API response

This 65-character response:

{"order":{"id":1042,"items":[{"sku":"A-1","qty":2}],"paid":true}}

The JSON formatter turns it into 130 characters with 2-space indentation:

{
  "order": {
    "id": 1042,
    "items": [
      {
        "sku": "A-1",
        "qty": 2
      }
    ],
    "paid": true
  }
}

The JSON Explorer lists order as an object with 3 keys, items as an array with 1 item, id and qty as numbers and paid as a boolean.

Trailing commas and other syntax errors

If you've ever had a script break because of a single misplaced comma, you know why a strict check matters. Format, Minify and Validate all run your text through the browser's JSON parser, which follows the grammar in RFC 8259 and rejects trailing commas, single-quoted strings, comments and unquoted property names. That makes the page a JSON validator as well as a JSON formatter. When parsing fails, the status bar shows Invalid JSON and the parser's own message. These are the messages Chrome gives; other browsers word them differently:

MistakeInputMessageFix
Trailing comma[1,2,]Unexpected token ']', "[1,2,]" is not valid JSONDelete the comma before the closing bracket
Single quotes{'id':1}Expected property name or '}' in JSON at position 1 (line 1 column 2)Use double quotes for keys and strings
Missing comma{"a":1 "b":2}Expected ',' or '}' after property value in JSON at position 7 (line 1 column 8)Add a comma between the two pairs
Comment after the data{"a":1} // noteUnexpected non-whitespace character after JSON at position 8 (line 1 column 9)Remove the comment; JSON has none

The position usually points just after the real mistake, so look at the character before it. The 7 most common JSON formatting errors covers more cases, and JSON formatter vs JSON validator explains when you need each.

Human-friendly debugging with the JSON Explorer

The JSON Explorer labels every value with its type (string, number, boolean, null, object or array) and shows how many items each object or array holds, so keys and values are easy to tell apart. Click an object or array to collapse it. The tree lists the first 50 entries at the top level and 30 inside each nested object or array, with a note saying how many more are hidden, and it shortens strings longer than 80 characters. The formatted output above it always contains everything.

In my own dev workflow, I use this tool daily to inspect API responses before piping them into my code. A token from a login response can go straight into the JWT decoder, and a spreadsheet export can be turned into JSON with the CSV to JSON converter first.

Format JSON online or in your editor

A JSON formatter online, or JSON beautifier as some sites call it, is quickest for a one-off response copied from a browser's network tab or a log file, since there is nothing to install. For files in a project, your editor's formatter or a command such as python3 -m json.tool data.json does the same job. To see what changed between two versions of a response, format both here with the same indent and paste them into the text diff checker. The other formatters are under developer tools.

Frequently Asked Questions

Can I minify JSON too?
Yes. The Minify button removes all whitespace and puts the data on one line. Because the tool parses the JSON and writes it out again, a few values can change in both Minify and Format: integers larger than 9,007,199,254,740,991 are rounded, 1.0 becomes 1, and when a key appears twice in one object only the last value is kept.
What happens if my JSON is invalid?
The output stays empty and the status bar shows Invalid JSON followed by your browser's error message. Chrome and Firefox add the line and column where parsing stopped. That is usually just after the real mistake: for a trailing comma it points to the closing bracket that follows the comma.
Is my JSON sent to a server?
No. The page uses the JSON.parse and JSON.stringify functions built into your browser, and the tree is drawn on the page. Nothing you paste is uploaded, so you can format API responses that contain customer data or access tokens.
Does the formatter accept comments or JSON5?
No. The parser follows strict JSON, so comments, trailing commas, single quotes, unquoted keys and values such as NaN are all reported as errors. Remove them, or convert the file with a JSON5 tool first, and the formatter will then accept the result.
Why does Validate say the root type is string?
Your input is a JSON string that contains JSON, which happens when a value has been encoded twice, for example "{\"id\":1}". It is valid, but it is one string, not an object. Parse it once in your code, or remove the outer quotes and backslashes, then format the inner JSON.
Can I format a very large JSON file?
There is no fixed size limit, so it depends on your browser and the memory available. Formatting a few megabytes is usually quick. The JSON Explorer only lists the first 50 top-level entries and 30 inside each nested item, but the formatted text in the output box always contains everything.