Skip to content

JSON Formatter

Format, validate and minify JSON in your browser, with plain-English errors at the exact line and column, and every number and string kept exactly as written.

  • Errors at the exact line
  • Numbers kept exactly
  • Format, minify, sort
  • Never used to train AI

Indent

Your JSON is checked in your browser and never sent anywhere. Numbers and text are kept exactly as written.

Indent2 spaces, 4 spaces or tab
ChecksRFC 8259, duplicate keys
FilesOpen .json up to 20 MB
RunsIn your browser

How to format JSON

The JSON formatter turns compressed or messy JSON into neatly indented, readable text, checks that it’s valid, and can shrink it back to one line. It works in your browser, so the data you paste never leaves your device.

  1. Paste your JSON in the box, or choose Open file to load a .json file (up to 20 MB). Sample loads an example to try.
  2. Read the result: it’s formatted as you type, with a green “Valid JSON” message, or a red message saying exactly what’s wrong and where.
  3. Choose the style: indent with 2 spaces, 4 spaces or tabs, and tick Sort keys A–Z if you want keys in alphabetical order.
  4. Minify to remove all spaces and line breaks, then Copy or Download .json.

Errors in plain words, at the exact spot

Most validators repeat the browser’s error, something like “Unexpected token } in JSON at position 27”. This one says what’s wrong in words, gives the line and column, and shows the line with a caret (^) under the problem. Common cases it explains:

MistakeExampleWhat the formatter says
Trailing comma[1, 2,]JSON doesn’t allow a comma before the closing bracket
Single quotes{'a': 1}JSON needs double quotes
Unquoted key{a: 1}Keys must be in double quotes
Missing comma{"a": 1 "b": 2}Is a comma missing between two entries?
Comments// noteComments aren’t allowed in JSON
JavaScript valuesNaN, undefinedUse a number, a string or null
Leading zero007Not written the JSON way (no leading zeros)
Unclosed bracket{"a": 1Add the missing }

Many of these come from copying JavaScript objects or config files that aren’t strict JSON. Fix the first error and the formatter checks again as you type, so you can work through a long file one problem at a time.

Turning code output into valid JSON

Text printed by programming languages often looks like JSON but isn’t quite:

  • Python prints dictionaries with single quotes and True, False and None. JSON needs double quotes and lower-case true, false and null. In Python, json.dumps(data) writes real JSON.
  • JavaScript object literals allow unquoted keys, single quotes, trailing commas and comments. JSON.stringify(data) writes real JSON.
  • Logs sometimes put several JSON objects one after another. JSON allows only one top-level value, so wrap them in [ ] with commas between, and the formatter will read them as a list.

The error messages point to the first place that needs changing, so you can fix these one at a time.

Your data is never changed

Many online formatters work by reading the JSON into JavaScript and writing it out again. That quietly changes data: JavaScript numbers can only hold integers exactly up to 9,007,199,254,740,991 (see MDN), so a long ID such as 9007199254740993 comes back as 9007199254740992. Decimals can change too: 4.50 becomes 4.5, and 1E+2 becomes 100.

This formatter uses its own strict parser that keeps every number and string exactly as you wrote it, and only changes the spaces and line breaks between them. It also warns when a number has more than 15 digits, because other programs that read your JSON may round it.

Validating JSON

“Valid” here means valid by the JSON standard, RFC 8259, and the formatter double-checks with your browser’s own JSON reader, so valid here is valid for web apps too. Two things are reported even when the JSON is valid:

  • Duplicate keys, such as "id" twice in the same object. The standard allows them, but most programs keep only the last value, which is rarely what was intended.
  • Very long numbers, as explained above.

It checks the syntax, not the meaning: whether the fields are the ones an API expects is a job for a JSON Schema, which this tool doesn’t check.

Beautify or minify?

  • Beautify (format, pretty print) adds line breaks and indentation so people can read it: for debugging API responses, reviewing config files, or writing documentation.
  • Minify removes every unnecessary space and line break so the file is as small as possible: for sending over a network, embedding in code, or storing many records.

Both keep exactly the same data; only the whitespace changes. The size before and after is shown under the result, along with the number of keys, list items and the nesting depth.

2 spaces, 4 spaces or tabs

It’s a matter of style. Two spaces is the most common choice for JSON on the web and in JavaScript projects; four spaces is common in Python projects and some style guides; tabs let each reader choose how wide indentation looks. If your team uses a code formatter, match its setting so files don’t change needlessly in version control.

Sorting keys

Sort keys A–Z orders the keys in every object alphabetically (by character code, so capital letters come before lower-case ones). It makes two versions of the same data easier to compare, and keeps generated files stable. The order of items in lists is never changed, because in a list the order is part of the data.

Where you’ll meet JSON

  • APIs: most web APIs send and receive JSON.
  • Config files: package.json, VS Code settings, many app and server configs.
  • Exports: data downloads from apps and services, browser bookmarks, analytics.
  • Logs: structured logs often write one JSON object per line.

For working with text around your data, the word and character counter helps check field lengths; to create test IDs or PINs, use the random number generator; for strong API test passwords, the password generator.

Private: safe for sensitive data

JSON often contains tokens, customer records or internal settings. Here it’s processed entirely in your browser: nothing is uploaded, logged, stored or used to train AI, and closing the page clears it. More in Trust and privacy. Even so, avoid pasting live secrets into any web page when you don’t need to.

Ask in plain words

  • “Why is this JSON invalid?”
  • “Pretty print this with 4 spaces and sorted keys.”
  • “Minify this JSON.”

Type it under the tool or in the AI workspace.

JSON formatter: questions and answers

How do I format JSON?

Paste it in the box above. It’s formatted as you type; choose 2 spaces, 4 spaces or tabs.

How do I check if JSON is valid?

Paste it: a green message means valid; a red one says what’s wrong, with the line and column.

Does formatting change my data?

No. Numbers and strings are kept exactly as written; only spaces and line breaks change.

Why are trailing commas an error?

The JSON standard doesn’t allow them, even though JavaScript does. Remove the comma before } or ].

Can JSON have comments?

No. Standard JSON has no comments; remove them, or keep notes in a separate field.

What does minify do?

It removes all unnecessary spaces and line breaks so the JSON is as small as possible, without changing the data.

Is my JSON sent anywhere?

No. Everything happens in your browser.

How large a file can I open?

Up to 20 MB from a file; very large text may take a moment to format.