JSON Formatter and Validator

Paste JSON to beautify it with the indent you prefer, minify it to a single line, or validate it and see what the parser objects to. It is free, updates as you type and runs entirely in your browser, so nothing you paste is uploaded.

JSON Formatter and ValidatorPrivate · runs on your device
Input
Words 0Characters 0Lines 0
Formatted JSON

Example: {"a":1,"b":[true,null]} → { "a": 1, "b": [ true, null ] }

How to use the JSON formatter

There is no Run button. The result updates as you type or paste, so you can adjust the settings and watch the output change.

  1. Paste your JSON into the Input box, or press Paste to read it from the clipboard. Try it loads a small example.
  2. Set Mode to Beautify for one key or array item per line, or to Minify for a single line with no spaces outside strings.
  3. Choose the Indent: 2 spaces, 4 spaces or Tab. It only affects Beautify.
  4. Tick Sort object keys if you want every object ordered alphabetically, at every depth.
  5. Read the status line under the boxes. It says "Valid JSON" with the total number of keys and the top-level type, or "Invalid JSON" followed by the parser message.
  6. Press Copy or Download .txt. Use as input moves the result back into the input box, so you can minify a document you have just sorted.

Parsing is done by your browser's own JSON engine, so the text never leaves the page. That makes it reasonable to inspect API responses and configuration files that contain tokens.

What happens to your data on the way through

The tool parses the text into values and writes it out again, rather than just adjusting spaces. That is why invalid input produces no output, and why a few details are normalised. Take {"a":1,"b":[true,null]}: Beautify with 2 spaces puts every key and array item on its own line, and Minify returns the original single line. Because the text is rewritten, expect these changes:

  • Numbers are printed in their shortest form, so 1.0 becomes 1 and 1e2 becomes 100.
  • Escapes are normalised: "é" becomes "é" and "\/" becomes "/".
  • If a key appears twice in one object, only the last value survives.
  • Integers above 9,007,199,254,740,991 lose digits: 12345678901234567890 comes back as 12345678901234567000. Keep identifiers that long as strings in the source.
  • Key order is kept as written unless Sort object keys is ticked.

Sorting is recursive. {"b":1,"a":{"z":1,"c":[3,1]}} comes out with a before b and c before z, while the array [3,1] keeps its order, because position inside an array carries meaning. Sorted output pairs well with the diff checker when you compare two exports.

Reading a validation error

When parsing stops, the status line shows the message from your browser's JSON parser, and the wording differs between Chrome, Firefox and Safari. In Chromium-based browsers it also gives a line and column, for example column 8 for {"a":1,}. That position is where the parser gave up, which is usually at or just after the real mistake. Most failures come from habits carried over from JavaScript or Python:

MistakeExampleFix
Trailing comma{"a":1,}Delete the last comma
Single quotes{'a':1}Use double quotes
Unquoted key{a:1}Quote the key
Comment{"a":1 // note}Remove it, JSON has none
Non-JSON value{"a":NaN}Use null or a string
Two documents{"a":1}{"b":2}Wrap in an array

Smart quotes pasted from a word processor and Python values such as True or None fail in the same way. A JSON Lines file, with one object per line, is not one valid document, so check it a line at a time.

Limits, and when another tool fits

The checker looks at syntax only. It does not compare a document with a JSON Schema, so a missing field or a string where you expected a number still counts as valid. Files that allow comments, such as tsconfig.json or editor settings, fail until the comments are removed. The whole document is held in memory at once: a few megabytes is comfortable, tens of megabytes may make the tab sluggish. The download is named json-formatter.txt, so rename it to .json if you need that extension.

Quick answers

Frequently asked questions

The questions people ask most, answered in plain words.

Is it safe to paste JSON that contains tokens or personal data?

The formatting is done by JavaScript running in your own browser tab, so the text is not sent to a server. You can confirm by loading the page, switching off your network connection and formatting a document. On a shared computer, press Clear when you finish so the input does not stay on screen.

Why does it say invalid JSON when my data looks correct?

The usual causes are a trailing comma, single quotes, an unquoted key, a comment, or a value such as NaN or undefined. Look at the character just before the reported position. Smart quotes copied from a document or chat app are another common cause, and they are easy to miss by eye.

Does beautifying or sorting change my data?

The values stay the same, but the text is rewritten. The number 1.0 becomes 1, escapes such as a Unicode sequence are replaced by the character, duplicate keys keep only the last value, and integers beyond 9,007,199,254,740,991 lose their final digits. Sorting changes object key order but never array order.

Can this tool validate JSON against a schema?

No. It checks that the text is well-formed JSON, meaning the syntax is correct, and nothing more. Whether a field is required, a value has the right type or a number is within range depends on a JSON Schema, which needs a schema validator in your editor, test suite or build pipeline.

Can I format JSON that contains comments?

Not directly, because standard JSON has no comment syntax and the parser rejects them. Files such as tsconfig.json use a looser variant that allows comments. Delete the comment lines first, paste the rest here, then put the comments back in your editor if you need them.