Skip to content

JSON Formatter & Validator

Paste JSON to beautify, minify or check it. Errors point to the exact line and column.

0 BSize
0Keys
0Depth
Input
Formatted JSON appears here.
Ready

Last reviewed:

What is JSON?

JSON (JavaScript Object Notation) is a text format for structured data, defined in RFC 8259. A document is built from six kinds of value: objects ({"key": value}), arrays ([1, 2, 3]), strings in double quotes, numbers, the literals true and false, and null. Objects and arrays can nest to any depth. It is the default payload format for REST APIs, webhooks, browser storage, many log pipelines and configuration files such as package.json.

The grammar is deliberately small and strict. Keys must be double-quoted strings, there are no comments, trailing commas are not allowed, and numbers cannot have leading zeros or be NaN or Infinity. That strictness is what makes JSON portable: a document that parses in one language parses the same way in every other. It is also why hand-edited JSON breaks so easily.

Whitespace between tokens is insignificant, so the same data can be written on one line (minified) or spread over many lines with indentation (pretty-printed). This tool converts between the two and tells you exactly where a document stops being valid JSON.

How to use this tool

  1. Paste JSON into the Input box, or click Paste to read it from your clipboard. Sample loads a small example.
  2. With Format as I type ticked (the default), the output updates on every keystroke. Untick it for very large documents and click Format when you are ready.
  3. Choose the indentation in the dropdown: 2 spaces, 4 spaces or Tab.
  4. Tick Sort keys to order object keys alphabetically at every level. Array order is never changed.
  5. Click Minify to get the same data on a single line with no extra whitespace.
  6. Switch between the Formatted and Tree tabs. The tree lets you expand and collapse objects and arrays and shows how many keys or items each one holds.
  7. Use Copy or Download (saved as formatted.json) to take the result with you. The header shows the input size, the number of object keys and the maximum nesting depth.

If the input is invalid, the status line under the input shows Invalid with the line and column of the problem and the parser's own message.

Examples

Pretty-printing a minified API response

Input:

{"id":42,"name":"Ada","roles":["admin","dev"],"active":true,"manager":null}

Output with 2-space indentation:

{
  "id": 42,
  "name": "Ada",
  "roles": [
    "admin",
    "dev"
  ],
  "active": true,
  "manager": null
}

Sorting keys, then minifying

With Sort keys ticked and Minify clicked, this input:

{"zeta": 1, "alpha": {"b": 2, "a": 1}, "list": [3, 1, 2]}

becomes:

{"alpha":{"a":1,"b":2},"list":[3,1,2],"zeta":1}

Nested keys are sorted too, but the array keeps its original order because array order is part of the data.

Locating a trailing comma

{
  "name": "api",
  "port": 8080,
}

In Chrome the tool reports Problem at line 4, column 1 with the message Expected double-quoted property name. The parser complains at the closing brace because, after a comma, it expected another key. The fix is on line 3: delete the comma after 8080.

Common errors and how to fix them

  • Trailing comma after the last item of an object or array. Reported at the closing } or ]. Delete the comma.
  • Single quotes such as {'id': 1}. JSON only accepts double quotes for keys and strings. This usually means the text came from a Python print(dict) or a JavaScript object literal; re-export it with json.dumps or JSON.stringify.
  • Unquoted keys such as {id: 1}. Chrome reports Expected property name or '}' at column 2. Quote every key.
  • Comments (// or /* */). JSON has none. Remove them, or keep the file as JSONC only if every tool that reads it supports that.
  • Unescaped control characters. A real tab or line break inside a string gives Bad control character in string literal. Write \t and \n instead, which a serializer does automatically.
  • Leading zeros and special numbers. 007, .5, +1, NaN and Infinity are invalid. Use 7, 0.5, 1, or null, or send the value as a string.
  • An HTML page instead of JSON. Unexpected token '<' at position 0 means you pasted (or your code received) an error page or login page. Check the HTTP status of the response.
  • Byte order mark. Some Windows editors put an invisible BOM at the start of a file. This tool trims it before parsing, but JSON.parse in your own code will reject it, so save files as UTF-8 without BOM.

When developers use this

  • Reading a single-line response copied from the browser network tab, curl or a log line before deciding which fields to use.
  • Finding the exact spot where a hand-edited config file, test fixture or package.json became invalid.
  • Normalising two payloads (same indentation, sorted keys) so a text diff shows only real differences, for example when an API response changed between releases.
  • Minifying a JSON document before putting it into an environment variable, a query parameter or a single-line log message.
  • Checking the depth and size of a document that a client struggles with, such as a webhook body that exceeds a limit.
  • Exploring an unfamiliar, deeply nested response in the tree view to find the path to one value.

Privacy and how it works

Parsing and formatting use the JSON.parse and JSON.stringify functions built into your browser, running in this tab. The text you paste is not sent to our servers, stored or logged, and the page keeps working if you go offline after it has loaded. That matters because JSON pasted during debugging often contains access tokens, customer records, internal hostnames or API keys. Even so, follow your company's data rules, and prefer redacted samples when you share results with others.

Limitations

  • Very large numbers lose precision. JavaScript stores numbers as 64-bit floats, so an ID like 9007199254740993 is displayed as 9007199254740992 after formatting. If exact digits matter, keep such values as strings in your JSON.
  • Duplicate keys are accepted and the last value wins, which is what JSON.parse does. The formatter will not warn you about them.
  • JSON5, JSONC and NDJSON (one document per line) are not standard JSON and are rejected.
  • Error wording comes from your browser's parser, so Firefox and Safari phrase messages differently from Chrome, although the line and column are always shown.

FAQ

Is my JSON uploaded anywhere?

No. Everything happens with JavaScript in your browser tab, and there is no server endpoint that receives your input. You can confirm this in your browser's developer tools: no network request is made when you format.

Why does the error point to the line after my mistake?

The parser reports the position where it first noticed something was wrong. For a trailing comma or a missing closing quote, that is the next token, which can be on the following line. Start at the reported position and look backwards.

Does Sort keys change my data?

Only the order of keys inside objects, which has no meaning in JSON. Values, types and the order of array items stay exactly the same. Sorting is useful before comparing two documents or committing a file, because it removes key-order noise from diffs.

What is the difference between Format and Minify?

Both produce the same data. Format adds line breaks and the indentation you chose so people can read it; Minify removes every optional space and line break so the document is as small as possible for storage or transport.

What do the Keys and Depth numbers mean?

Keys is the total number of object keys in the whole document, including nested objects (array items are not counted). Depth is how many levels deep the deepest value is nested. A response with unexpected depth often points to an accidental double-wrapped object.

Can it handle large files?

Documents of a few megabytes format quickly in modern browsers. For larger files, untick Format as I type so the tool does not re-parse on every keystroke, and use the Formatted view rather than the tree, which creates an element for every value.

Why do my comments disappear or cause an error?

Standard JSON does not support comments, so a document containing them is invalid and cannot be formatted. If you need comments in configuration, YAML supports them; you can convert between the two with the YAML ⇄ JSON tool.

Guides