On-device AI — professional-grade, fully private.

Documents

How to Format JSON Online (and Fix the Errors That Break It)

Paste messy JSON and get readable, indented JSON. Fix trailing commas, single quotes, unquoted keys and comments, pick an indent, and handle big files.

Updated November 1, 20268 min read

To format JSON, paste it into the JSON formatter, choose an indent of 2 spaces, 4 spaces or a tab, and press Format JSON. A single unreadable line becomes an indented outline you can read, and if the JSON is broken you get the line and column of the problem instead of a vague failure. The same page minifies, sorts keys and repairs the usual mistakes. This guide covers what formatting does and does not change, how to fix each common syntax error, which indent to choose, and what to expect with large files.

Format, validate or minify?

You want to…UseWhat you get
Read or edit a messy or one-line documentFormatter in Format modeIndented, line-broken JSON
Know whether a file is valid, and every place it is notValidatorA list of errors with line, column and a caret
Shrink JSON before sending or storing itMinifier or Minify in the formatterOne compact line, same data
Make two exports comparableSort keysThe same key order every time

The three jobs share one rule: the data stays exactly the same and only the whitespace around it changes. Formatting adds line breaks and indentation, minifying removes them, and validating reads the document without changing it at all.

Formatting JSON, step by step

1

Paste or add the JSON

Open the JSON formatter. Drop a .json, .jsonc, .ndjson, .jsonl or .txt file onto the page, choose one with Browse files, or open the paste panel and paste straight from your clipboard.

2

Pick Format and an indent

Under Output choose Format for readable JSON. Under Indent choose 2 spaces, 4 spaces or Tab. Everything in this panel is free.

3

Read the result

The Text view shows highlighted output. Tree lets you collapse branches and copy the path of any value, and Stats reports depth and counts of objects, arrays, strings and numbers.

4

Fix errors if there are any

A broken document shows a message, a line, a column and the offending line with a caret under the character. If the problem is one the tool can repair, tick Repair invalid JSON and it lists each change it made.

5

Copy or download

Press Copy for the clipboard or Download for a file. Nothing is sent to a server; it all runs on your device.

Pretty print, minify, sort keys and repair broken JSON with every formatting option included. Free: one file up to 25 MB. Pro: up to 20 files at once, downloaded as one ZIP. It all runs on your device, not our servers.

Format JSON

The syntax errors that break JSON, and how to fix each

JSON is stricter than the JavaScript it looks like. Most failures come from a handful of habits carried over from code, config files or Python output. Here they are, roughly in order of how often they turn up.

MistakeExampleFix
Trailing comma{"a": 1,}Delete the comma before the closing brace or bracket
Single quotes{'a': 'b'}Use double quotes for keys and strings
Unquoted keys{a: 1}Wrap every key in double quotes: {"a": 1}
Comments// note or /* note */Remove them; JSON has no comment syntax
Python or JavaScript valuesTrue, False, None, NaN, undefinedUse true, false and null; JSON has no NaN
Raw line break in a stringA real new line inside quotesWrite it as \n inside the string
Missing comma{"a": 1 "b": 2}Add a comma between members

For the first five you do not have to edit by hand. Tick Repair invalid JSON and press Repair and format. Repair is off by default because it is a decision about your data: when it is on, the Stats view lists every change, such as how many trailing commas it removed or how many strings it converted from single to double quotes, so you can check that you agree before you download. It does not touch the inside of your strings, so a comma or a quote within a quoted value is never mistaken for structure.

If you would rather see all the problems before changing anything, the JSON validator keeps going after the first fault and reports each one with its line and column. A normal parser stops at the first, which means a file with forty mistakes takes forty rounds of fixing.

Choosing an indent

The indent changes only whitespace, never the data, so the choice is about who will read the file. Minify has no indentation at all, so the Indent control is switched off while Minify is selected.

IndentBest forTrade-off
2 spacesWeb projects, config files, most API documentationCompact; deeply nested data can still be hard to follow
4 spacesReading very nested data, teaching materialWider lines; more horizontal scrolling
TabTeams whose style guide uses tabsWidth depends on the viewer, so it looks different in different editors
MinifySending, storing or embeddingSmallest size; unreadable without a formatter

If the file lives in a repository, follow what the rest of the project uses so a reformat does not turn every line into a change. Under Line ending, choose LF for version control and CRLF only for files that will be opened in Windows Notepad.

Sort keys, duplicates and long numbers

Many online formatters read your JSON into program values and write it back out. That round trip can quietly alter data: an integer larger than 9,007,199,254,740,991 is rounded, so an ID such as 12345678901234567890 comes back as a different number, and a repeated key keeps only its last value. This formatter copies every number, string and key from your original text character for character and changes only the spacing, so long IDs, trailing zeros and key order survive. The Stats view even tells you how many numbers would have lost precision in a normal formatter.

Sort keys offers Off, A to Z, Z to A and Natural. Natural order treats digit runs as numbers, so item2 comes before item10. Sorting is recursive through nested objects, and arrays always keep their order, because the order of an array is data. Sort before you compare two exports and the differences you see are real value changes. For a side by side comparison use the JSON diff. Duplicate keys defaults to Keep both, the only option that does not delete anything; Keep first and Keep last are there when you want to resolve them on purpose.

Large files

Free handles one file up to 25 MB, which covers nearly every API response, configuration file and export. Formatting runs in the background so the page stays responsive, and for very large documents the preview shows the first part and the download holds the whole thing. Indented output is bigger than the input, because every level adds spaces. Formatting an API payload with 2 spaces can make it close to twice as large, so a 20 MB file may produce a result well past 30 MB.

If a document is deeply nested, indentation can grow very fast, and the tool will tell you the indented result would be too large to build. Choose Minify in that case. When you only need to find something in a huge response, the Tree view collapses branches so it fits on a screen, and the JSON viewer is built for exploring big documents. Pro lifts the per-file size limit to what your device can handle and allows up to 20 files in one go.

Files with one record per line

Logs and database exports are often JSON Lines, also called NDJSON: one complete JSON value per line with no wrapping array and no commas between records. A normal formatter calls that invalid because there is content after the first record. This one detects it. By default each record stays minified on its own line so the file remains valid JSON Lines. If you need a single document, set JSON Lines to Single array and the records are wrapped into one array and indented with your chosen setting.

A quick checklist when JSON will not parse

  1. 1Read the line and column in the error, then look at the character just before it as well; many errors are reported where the parser noticed them, not where you made them.
  2. 2Check quotes: every key and every string must use straight double quotes, not single or curly ones.
  3. 3Look for a comma at the end of the last item in an object or array, and for a missing comma between two items.
  4. 4Search for comments, True, False, None, NaN and undefined and replace them with valid JSON.
  5. 5Make sure every opening brace or bracket has its match, and that the document is one value, not two pasted together.
  6. 6If the JSON came inside a string with backslashes in front of every quote, it has been escaped; use the JSON escape tool to unescape it first.

Frequently asked questions

How do I format JSON online for free?

Paste your JSON into the formatter or drop a file, choose Format and an indent of 2 spaces, 4 spaces or a tab, and press Format JSON. Every formatting option is free on files up to 25 MB, and you can copy or download the result.

How do I fix invalid JSON?

Read the line and column in the error message. The usual causes are trailing commas, single quotes, unquoted keys, comments and Python values like True or None. Tick Repair invalid JSON to fix these automatically; the tool lists each change it made so you can check it.

What is the difference between formatting and validating JSON?

Formatting rewrites the whitespace so the document is easy to read. Validating only checks whether the document is valid and reports every error with its position. The formatter also reports a syntax error when it cannot read the file; the validator is better when you want a full list of faults.

Does formatting change my data?

No. Only spaces, tabs and line breaks change. Numbers, strings and key order are copied exactly from your text, including very long integers and numbers like 1.10, which are not rounded or respelled.

Should I use 2 spaces, 4 spaces or tabs?

Use whatever the rest of your project uses. Two spaces is common in web projects and keeps lines short, four spaces is easier to read for deeply nested data, and tabs suit teams that prefer them. The choice never affects the data.

Can I format a very large JSON file?

Yes. Free handles one file up to 25 MB. Pro lifts the per-file limit to what your device can handle and formats up to 20 files at once as a ZIP. If indenting would make the result too large, use Minify instead.

Keep reading

More in Documents →