JSON Formatter

Paste JSON to pretty-print it, minify it or explore it as a collapsible tree. Syntax errors are reported with the exact line and column, and everything runs in your browser.

100% freeNo sign-upRuns in your browserWorks on mobile
Checked as you type. Your data never leaves this browser.
0 BInput size
–Output size
–Keys
–Max depth

How to use the JSON Formatter

  1. Paste JSON into the input box, drop a .json file onto it, or click Open file.
  2. Check the status bar. Valid JSON is formatted instantly; invalid JSON shows the line, the column and a hint on how to fix it.
  3. Pick 2 spaces, 4 spaces or tabs, tick Sort keys for alphabetical order, or click Minify for one compact line.
  4. Switch the output to Tree to fold and unfold objects and copy the path of any value.
  5. Click Copy or Download .json to take the result with you.

Features

  • Strict RFC 8259 validation with line, column and a plain-English fix hint
  • Beautify with 2 spaces, 4 spaces or tabs, or minify to a single line
  • Optional alphabetical key sorting at every nesting level
  • Collapsible tree view with a copyable path for every value
  • Keeps large numbers and escape sequences exactly as written
  • Handles multi-megabyte files without freezing the page

What a JSON formatter does

JSON (JavaScript Object Notation) is the format most web APIs, configuration files and log pipelines use to exchange data. Machines usually write it as one long line with no spaces, which is efficient but almost impossible to read. A formatter adds line breaks and indentation so every object and array sits on its own level, letting you see the structure at a glance, spot a missing field or compare two responses. Minifying does the reverse: it strips every optional space so the data is as small as possible before you send or store it.

The syntax rules that catch people out

JSON looks like JavaScript, but the rules defined in RFC 8259 are much stricter. These are the mistakes this validator sees most often, and how to fix them:

MistakeInvalidValid
Unquoted or single-quoted keys{name: 'Ada'}{"name": "Ada"}
Trailing comma[1, 2, 3,][1, 2, 3]
Comments// noteRemove them, or store notes in a field
Leading zeros{"zip": 01101}{"zip": "01101"}
Special numbersNaN, Infinity, undefinednull or a real number
Raw line breaks in stringsA string split over two linesWrite the break as \n

How to read an error message

The error box gives the line and column where the parser first realized something was wrong, a copy of that line with a caret under the exact character, and a suggestion. Keep in mind that the reported spot is where the problem was noticed, which is sometimes just after the real mistake. A missing comma, for example, is reported at the start of the next property, because that is the first character that cannot belong to the previous value. If a bracket is never closed, the message tells you the line where it was opened, which is usually far more useful than “unexpected end of input”. Click Go to error to jump straight to the character in the input box.

Format, minify or sort?

  • Format when you are reading, debugging or committing JSON to version control. Two spaces is the most common style in JavaScript projects; four spaces matches Python’s json.dumps(indent=4).
  • Minify before embedding JSON in a request, a data attribute or a database column. Removing whitespace from a pretty-printed file often shrinks it by 20–40%.
  • Sort keys when you want to compare two documents. Sorting puts properties in the same order at every level, so a text comparison shows only real differences. Arrays are never reordered, because their order carries meaning.

Why your numbers stay exactly as typed

Many online formatters parse JSON into JavaScript values and print it back out. That silently rounds integers above 9,007,199,254,740,991 (253 − 1), the largest whole number a JavaScript number can hold exactly, so an order ID like 9007199254740993 comes back as 9007199254740992. This tool reformats the original text token by token instead, so big IDs, trailing zeros such as 1.50 and escape sequences such as \u00e9 come out exactly as they went in.

Duplicate keys

The JSON standard says object names should be unique but does not forbid repeats. In practice most parsers keep only the last value, so a duplicate usually means data is being lost. The validator flags the first duplicate it finds with its line number while still treating the document as valid.

Need a different shape? Turn an array of records into a spreadsheet with the JSON to CSV converter, or translate configuration files with the YAML to JSON converter.

Frequently asked questions

Is my JSON uploaded to a server?

No. Validation, formatting and the tree view all run in your browser with JavaScript, so API responses, tokens and customer data never leave your device.

Why does the error point to the line after my mistake?

A parser reports the first character it cannot accept. With a missing comma, that is the start of the next property, so look at the end of the previous line as well as the highlighted spot.

Can it repair invalid JSON automatically?

It does not guess, because an automatic fix can change your data. Instead, each error explains exactly what to change, such as replacing single quotes with double quotes or deleting a trailing comma.

How large a file can I format?

Files of several megabytes work well. Above about 1.5 MB the tool waits for you to press Format instead of reformatting on every keystroke, and the tree view shows large arrays 200 items at a time.

What order does Sort keys use?

Keys are sorted by character code at every level, so uppercase letters come before lowercase ones. This is the same order used by the JSON Canonicalization Scheme (RFC 8785). Array items keep their original order.

Does JSON allow comments or trailing commas?

Standard JSON does not. Formats such as JSONC (used for VS Code settings) and JSON5 allow them, but strict parsers will reject the file, so remove them before sending the data to an API.

More developer tools

Other free tools you might need next.

View all 24