How to format JSON
- Paste JSON into the editor, drop a
.jsonfile on it, or click Upload. - Click Format (or
Ctrl+Enter). Choose 2 spaces, 4 spaces or tabs in the Indent menu. - Check the status bar. A green "Valid JSON" means the syntax is correct; otherwise it tells you where the problem is.
- Copy or download the result from the right panel.
JSON rules that catch people out
Most "invalid JSON" errors come from habits carried over from JavaScript or Python. The validator checks for all of these:
- Keys and strings need double quotes.
'single quotes'are not allowed. - No comma after the last item:
[1, 2, 3,]is invalid. - No comments. Neither
//nor/* */is part of JSON. - Only
true,falseandnull. NotTrue,None,undefinedorNaN. - A line break inside a string has to be written as
\n. - Numbers can't have leading zeros (
007) or end with a dot (5.). - There is exactly one root value. Two objects one after another need to be wrapped in an array.
Fixing broken JSON
Repair fixes the mistakes that come from hand-editing, from copying JavaScript or Python code, or from a response that got cut off. It runs in your browser and lists everything it changed. This input, pasted from a Python script:
// exported from the admin tool
{
name: 'Ada Lovelace',
"active": True,
"manager": None
"langs": ["en", "fr",], comes back as:
{
"name": "Ada Lovelace",
"active": true,
"manager": null,
"langs": [
"en",
"fr"
]
} It removed the comment, quoted the key, switched to double quotes, converted True and None, added the missing comma, dropped the trailing comma and closed the object. Repair also handles:
- A missing
{,}or], including JSON that was cut off halfway - Curly quotes (
“ ”) from word processors and chat apps, and quotes inside strings that weren't escaped undefined,NaNandInfinity, which becomenull- Markdown code fences, JSONP wrappers like
callback({...})and log text in front of the JSON - MongoDB shell values such as
ObjectId("…")andISODate("…") - Several JSON objects one after another (JSON Lines), which are wrapped in an array
If something still can't be fixed automatically, the validator points to the exact line and column that is left.
Pretty-print or minify?
Pretty-printed JSON is for people. There's one value per line, indented by depth, which makes it easy to read and to compare in a code review. Minified JSON is for machines. It fits on one line and is smaller, which helps in request bodies, environment variables and anywhere a single line is required. After you click Minify, the status bar shows the new size and how many bytes were saved.
Large numbers are kept exactly
JSON itself has no limit on number size, but JavaScript can only store whole numbers exactly up to 9,007,199,254,740,991. Database IDs, social media post IDs and money amounts often go past that. Tools built on JSON.parse round them without telling you. This formatter never converts numbers, so 12345678901234567890 stays 12345678901234567890 and 1.50 stays 1.50.
Finding your way around big documents
Switch the right panel to Tree View to see the structure. Every object shows how many properties it has and every array how many items, so you can find the part you need without scrolling through thousands of lines. In the editor, click the small arrows next to the line numbers to fold a block down to { … }.
Frequently asked questions
What is the difference between a JSON parser, formatter and validator?
A parser reads the text and builds the data from it. A validator tells you whether that worked and, if not, where it failed. A formatter writes the data back out with consistent indentation. This page does all three in one step.
My JSON is valid here, so why does my application still reject it?
The syntax is fine, but the content doesn't match what the application expects: a required field is missing, a number was sent as a string, or the nesting is different. That is a schema problem, not a syntax problem.
Can I format JSON with comments (JSONC)?
Comments aren't valid JSON, so the validator will flag them. Click Repair to remove // and /* */ comments, then format as usual.
Does it support JSON Lines (NDJSON)?
Yes. Paste the lines and click Repair: each line becomes one item in a single JSON array, which you can then format, browse as a tree or convert.