DevKitHub

JSON & Data

JSON Formatter & Beautifier

Paste JSON to reformat it with consistent indentation. Syntax errors are reported with the exact line and column so you can jump straight to the problem.

1 line
9 lines

This tool runs entirely in your browser. Your input is never uploaded, stored or logged.

How it works

Formatting is a parse-and-reprint, not a text transformation. The input is parsed into real values — objects, arrays, numbers, strings — and then written back out with consistent indentation. Nothing is rewritten with regular expressions, so a string containing a brace or a comma cannot confuse it.

Because the document is fully parsed first, invalid input cannot be partially formatted. Either the whole document is valid and you get formatted output, or parsing stops at the first error and you get its line and column. That is why the tool never returns half-formatted text.

Reprinting normalises some things without changing meaning: numbers lose insignificant trailing zeros, escape sequences are written in their shortest valid form, and duplicate keys collapse to the last one that appeared. JSON objects are unordered by specification, so none of that changes what the document means to a parser.

Common problems

Every example below is run against this tool in our test suite, so what it says here is what the tool actually does.

Expected double-quoted property name

{
  "a": 1,
}
Why:
A trailing comma after the last member. Valid in JavaScript object literals and in JSON5, not in JSON.
Fix:
Delete the comma before the closing brace or bracket.

Expected property name or '}'

{'a': 1}
Why:
Single-quoted keys or strings. JSON requires double quotes for both.
Fix:
Replace every single quote with a double quote.

Unexpected token

{a: 1}
Why:
An unquoted key. JavaScript allows bare identifiers as keys; JSON does not.
Fix:
Quote the key: {"a": 1}.

Unexpected token N

{"n": NaN}
Why:
NaN and Infinity are JavaScript number values with no JSON equivalent. JSON.stringify writes them as null, so they often appear in files that were built by hand.
Fix:
Use null, or a string, and handle it in your code.

Frequently asked questions

Is my JSON sent to a server?
No. Formatting runs entirely in your browser using the built-in JSON parser. Your input never leaves your device and is not logged.
Why does it say "Unexpected token" on valid-looking JSON?
The most common causes are trailing commas, single quotes instead of double quotes, and unquoted keys. All three are valid JavaScript but invalid JSON. The error shows the line and column where parsing stopped.
Does sorting keys change my data?
It reorders object keys alphabetically but never changes values, and array order is always preserved. JSON objects are unordered by specification, so sorted output is equivalent data.

Last updated