JSON Formatter and Validator

Prettify, minify and validate JSON — with the exact line and column of any error, and a tree view for finding your way around a large document.

Runs entirely in your browser. Nothing you type is uploaded.

273 B in · 10 lines

Valid JSON. A object with 11 properties, nested 4 levels deep. Minifying saves 46 B.
3Objects
2Arrays
7Strings
1Numbers
1Booleans
1Nulls
{
  "service": "devbox-tools",
  "version": "1.0.0",
  "public": true,
  "limits": {
    "maxUploadBytes": null,
    "requestsPerMinute": 60
  },
  "regions": [
    "eu-central-1",
    "us-east-1"
  ],
  "contacts": [
    {
      "name": "Ada",
      "role": "maintainer",
      "email": "ada@example.com"
    }
  ]
}

What this does

  • Formats with 2 spaces, 4 spaces or tabs, so the structure is readable.
  • Minifies by stripping whitespace, and tells you how many bytes that saved.
  • Validates and, when something is wrong, names the specific mistake at the exact line and column.
  • Sorts keys alphabetically, which makes diffing two API responses possible.
  • Shows a tree with types, sizes, and a copyable accessor path for any node — users[0].name rather than counting brackets.

The JSON syntax rules people trip over

JSON is a deliberately small format. Almost every error comes from writing JavaScript, Python or YAML by accident.

Not valid JSONWhyFix
{"a": 1,}Trailing commaRemove the comma
{'a': 1}Single quotesUse double quotes
{a: 1}Unquoted keyQuote it: {"a": 1}
// noteComments are not part of JSONRemove, or use JSONC / JSON5
{"a": undefined}No undefined in JSONUse null, or omit the key
{"a": NaN}No NaN or InfinityUse null or a string
{"a": 01}Leading zeros are not allowedWrite 1, or quote it if it is an identifier
{"a": .5}A number must start with a digitWrite 0.5
{"p": "C:\Users"}\U is not a valid escapeDouble the backslash: C:\\Users

Each of these is explained individually in how to fix JSON parse errors.

Formatting on the command line

Useful when the document is too big to paste, or when you want this in a pipeline.

# jq — the standard tool, if you have it
jq . file.json                 # pretty-print
jq -c . file.json              # minify
jq -S . file.json              # sort keys

# Python, available almost everywhere
python -m json.tool file.json
python -m json.tool --sort-keys --indent 4 file.json

# Node
node -e 'console.log(JSON.stringify(require("./file.json"), null, 2))'

# Validate only, exit code 0 or 1
jq empty file.json

jq empty is the useful one for CI: it prints nothing on success and exits non-zero on a syntax error.

Frequently asked questions

Is my JSON uploaded anywhere?

No. Parsing, formatting and validation all happen in your browser using its own JSON parser. There is no server that could receive the document, which is the point — most JSON you actually need to inspect is a production payload you should not be pasting into someone else’s server.

How large a document can it handle?

Multi-megabyte documents are fine. Above roughly 500KB the tool stops reformatting on every keystroke and waits for you to click, because re-serialising a large document ten times a second is exactly what makes other formatters freeze. The tree viewer also renders a bounded number of nodes and says so when it truncates; the formatted output is always complete.

What does “Unexpected token” actually mean?

That the parser reached a character it could not use at that point. The usual causes are a trailing comma before a closing bracket, single quotes instead of double, an unquoted key, or a comment — all valid JavaScript, none valid JSON. This tool names the specific cause and points at the line and column instead of giving you a character offset.

Why is my trailing comma rejected?

Because JSON does not allow one, even though JavaScript, JSON5 and most linters do. It is the single most common JSON syntax error. If you control the consumer, JSON5 or JSONC will accept it; if you do not, remove the comma.

Can I use comments in JSON?

Not in standard JSON. // and /* */ are both rejected by any conforming parser. Some ecosystems use JSONC (VS Code settings) or JSON5 which do allow them, but a file with comments is not portable JSON — if it has to be consumed generally, move the explanation into a "_comment" property or out into documentation.

What does sorting keys do?

It reorders object properties alphabetically, recursively. Useful for diffing two documents that differ only in key order — a very common false positive in API response comparisons. Array order is left alone, because in JSON that is data rather than presentation.

Does minifying change my data?

No. It removes whitespace between tokens, nothing else. The parsed value is identical, which is why the round trip through format and minify is safe. Note that key order is preserved and numbers are re-serialised from their parsed value, so 1.0 becomes 1 and 1e3 becomes 1000.

Why did my large integer change?

JavaScript numbers are IEEE 754 doubles, so any integer beyond 2^53 − 1 (9007199254740991) loses precision — a common problem with Twitter-style IDs and database bigints. This affects every JavaScript-based JSON tool, including this one. If your IDs are that large, they should be transmitted as strings.