Format, validate, minify

Tidy up some JSON.

Paste JSON. Format with 2 or 4 spaces, minify, sort keys, or escape for safe embedding in a JS string literal. Validation pinpoints line and column on error. Pure browser; no login.

Load file
Output

Formatting and validating JSON

JSON is the text format most APIs, configuration files and log pipelines use to exchange data. Machines often send it as one long line with no spaces, which is efficient but unreadable. A formatter re-indents it into a tree you can scan, and a validator tells you exactly where it breaks when it is not valid JSON.

This tool parses your input with the browser's own JSON parser, the same one your JavaScript code uses, so if it passes here it will parse there. Nothing is uploaded, which matters when the JSON holds customer records or tokens.

How to use it

  1. Paste JSON into the input box, or load a .json file from your device.
  2. Choose a mode: Format (2 spaces), Format (4 spaces), Minify, or Sort keys.
  3. If the JSON is valid, the result appears on the right, ready to copy. If not, the tool shows the parser's message plus the line and column where it stopped.
  4. Fix the reported spot and the result appears as soon as the input parses.

Example: sorting keys in a small object

Input
{"name":"Ada","tags":["math","code"],"born":1815}
Output
{
  "born": 1815,
  "name": "Ada",
  "tags": [
    "math",
    "code"
  ]
}

Sort keys orders object keys alphabetically at every level but keeps arrays in their original order, because order inside an array carries meaning.

The errors you will meet most

JSON is stricter than JavaScript. Keys and strings need double quotes, so {'a': 1} fails. A comma after the last item, as in [1, 2,], fails. Comments, undefined, NaN and Infinity are not allowed. Numbers cannot start with a leading zero or a plus sign.

When the error points at the very end of the input, something was never closed: a missing } or ], or a string whose closing quote is absent. When it points at a line that looks fine, look at the end of the line before it.

When to minify and when to sort

Minify removes every optional space and line break. Use it before embedding JSON in a URL, an environment variable or a request body where size counts. Formatting the data again later gives back the same structure.

Sort keys is useful before comparing two JSON documents. Two API responses with the same data but keys in a different order look completely different in a diff; sorted, only the real changes stand out.

A note on very large numbers

JavaScript stores numbers as 64-bit floating point, so integers above 9,007,199,254,740,991 lose precision when parsed. Long numeric IDs from some APIs can change silently when formatted by any JavaScript-based tool. If exact digits matter, have the API send such IDs as strings.

Questions

Does formatting change my data?

No, only the whitespace. Values, nesting and array order stay the same. Sort keys reorders object keys, which JSON treats as unordered anyway.

Why does valid-looking JavaScript fail here?

Object literals in JavaScript allow single quotes, unquoted keys, comments and trailing commas. JSON allows none of them.

Is my JSON sent anywhere?

No. Parsing and formatting happen in this browser tab. You can use the tool offline once the page has loaded.