Advertisement
Advertisement

JSON Formatter & Validator

Paste JSON to pretty-print it, squeeze it onto one line, or find exactly where it breaks.

🔒 Your JSON is processed by your own browser. Nothing you paste or open is uploaded.
Indent:

How to use the JSON Formatter & Validator

  1. Paste your JSON into the input box, or click Open file to load a .json file from your device.
  2. Pick an indent (2 spaces, 4 spaces or tab) and tick Sort keys A–Z if you want object keys in alphabetical order.
  3. Click Format to pretty-print, Minify to remove all extra whitespace, or Validate just to check it.
  4. If something is wrong, read the message: it gives the line and column and shows the spot. Click Jump to error to highlight it in the input.
  5. Switch to Tree view to fold and unfold nested objects, then Copy or Download the result.

How it works

The tool reads your text with its own strict parser that follows the JSON grammar in RFC 8259: objects in braces, arrays in brackets, strings in double quotes, numbers without leading zeros, and the literals true, false and null. Because the parser is ours rather than the browser's built-in one, it can say why something failed and where, in the same words on every browser. It also recognizes common slip-ups and names them: single-quoted strings, unquoted keys, trailing commas, comments, and values like NaN or undefined that JavaScript allows but JSON does not.

Formatting rewrites the same data with consistent spacing. Two details make this formatter safer than a quick JSON.stringify round trip: numbers are copied exactly as written, so a 19-digit ID such as 12345678901234567890 is not rounded, and keys stay in their original order (unless you ask for sorting), even keys that look like numbers. If an object repeats a key, you get a warning, because most programs silently keep only the last one.

Example: the input {"b":1,"a":[true,null]} with 2-space indent and sorted keys becomes {, "a": [, true,, null, ],, "b": 1, } on separate lines. Minify turns it back into a single line with no spaces. Files of several megabytes are fine; the tree view only builds the branches you open, so very large documents stay responsive.

Frequently asked questions

Why does it say "trailing comma"?
JSON does not allow a comma after the last item in an object or array, such as [1, 2, ]. JavaScript and some config formats accept it, but strict JSON parsers do not. Delete the comma just before the closing bracket.

Can it fix my JSON automatically?
No. Guessing what was meant can quietly change your data, so the tool points to the exact line and column instead. Most fixes are one character: a missing comma, a missing quote, or a stray bracket.

Will formatting change my numbers or strings?
Numbers are copied character for character. Strings keep the same text, but escape sequences may be written differently; for example \u00e9 becomes é, which is the same character.

How big a file can I format?
Files of 5 MB or more work in a modern desktop browser. The limit is your device's memory, since everything happens locally. Phones handle smaller files more comfortably.

Does it support JSON with comments (JSONC) or JSON5?
No. Those are different formats. The validator reports comments as errors so you know the file is not plain JSON. Remove the comments first if the file needs to be read by a strict JSON parser.

Advertisement

You might also need