What is JSON?
JSON (JavaScript Object Notation) is a plain-text format for structured data, defined by RFC 8259. It is the usual format for REST API requests and responses, configuration files such as package.json, structured logs, and document databases.
A JSON document is built from six kinds of value: objects ({ }), arrays ([ ]), strings in double quotes, numbers, true and false, and null. Whitespace between values has no meaning, which is why the same data can be minified onto one line or spread across many lines to be readable.
How to format JSON
- Paste your JSON into the input, select Open file, or drop a file onto the editor. Files are read on your device, not uploaded.
- Choose an indentation: 2 spaces, 4 spaces or tabs.
- Select Format, or press Ctrl + Enter (⌘ + Enter on Mac). The formatted result appears next to the input.
- If the input has a syntax error, it is underlined as you type, and the message shows its line and column with a suggested fix. Show in input moves your cursor to it.
- Select Copy to put the result on your clipboard, or Download to save it as a file.
Before and after
Minified JSON from an API response:
{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true,"last_login":null}
The same data after formatting with 2 spaces:
{
"id": 42,
"user": {
"name": "Ada",
"roles": [
"admin",
"dev"
]
},
"active": true,
"last_login": null
}
What this formatter changes, and what it doesn't
Only whitespace changes. Many online formatters work by running JSON.parse and then JSON.stringify, which quietly alters data on the way through:
- Integers larger than 9,007,199,254,740,991 are rounded.
12345678901234567890comes back as12345678901234567000, which breaks IDs from systems like Twitter/X, Discord and many databases. - Numbers are rewritten:
1.50becomes1.5and1E3becomes1000. - Escape sequences are decoded:
"café"becomes"café". - When a key appears twice in an object, only the last value is kept.
This tool reads your JSON with its own parser and keeps the original text of every string and number, so none of that happens. If your data contains a duplicate key or an integer that JavaScript can't store exactly, you'll see a note under the result, because other software reading the same JSON may handle it differently.
Repairing almost-JSON
JSON copied from code, logs or chat often isn't quite valid. Repair fixes the common problems and lists every change it made, with its line and column:
- Comments (
//,/* */and#) and trailing commas are removed. - Single-quoted and curly-quoted strings get straight double quotes.
- Unquoted property names are quoted, and missing commas between items are inserted.
- Python and JavaScript values become JSON:
Truetotrue,None,NaNandundefinedtonull. - Numbers like
+5,.5and0x1Fare rewritten as5,0.5and31. - Wrappers are removed: JSONP callbacks such as
callback({...}), Markdown code fences, andconst config = {...};assignments.
For example, this JavaScript object:
const settings = {
// UI options
theme: 'dark',
plugins: ['git', 'lint',],
experimental: undefined,
};
repairs to valid JSON:
{
"theme": "dark",
"plugins": [
"git",
"lint"
],
"experimental": null
}
Repair never guesses. A number with leading zeros such as 02134 is left alone, because it may be a ZIP code or ID that should be a string. Format and Minify never repair anything: they stop at the first error so you can see it.
Exploring JSON as a tree
Select the Tree tab to browse the result as a collapsible tree. Use the arrow keys to move and expand, or Find in tree to highlight every matching key and value. Select any row to see its JSONPath, such as $.tools[0].slug, and copy the path or the value. Large numbers are shown exactly as written, not rounded.
Common JSON errors and how to fix them
Trailing comma
{"a": 1, "b": 2,} is invalid. JavaScript allows a comma after the last item, JSON does not. Remove the comma before the closing } or ].
Single quotes
{'name': 'Ada'} is invalid. JSON strings and property names must use double quotes: {"name": "Ada"}. This often happens when pasting a Python dictionary or a JavaScript object.
Unquoted property names
{name: "Ada"} is a valid JavaScript object but not valid JSON. Wrap every property name in double quotes.
Missing comma
{"a": 1 "b": 2} needs a comma between the two properties. The error points at the start of the property after the missing comma.
Comments
JSON has no comment syntax, so // and /* */ are errors. Formats such as JSONC and JSON5 allow comments, but a standard JSON parser will reject them.
Values from other languages
True, False and None (Python) and NaN, Infinity and undefined (JavaScript) are not JSON values. Use true, false and null, or store special numbers as strings.
Leading zeros
{"zip": 02134} is invalid because JSON numbers can't start with a zero. If the leading zero matters, as in ZIP codes, phone numbers and IDs, store the value as a string: "02134".
Line breaks inside strings
A string must be on one line. Write a line break as \n instead of pressing Enter inside the quotes. This error also appears when a closing quote is missing.
Choosing an indentation style
Two spaces is the most common choice for JSON: it is what JSON.stringify(data, null, 2) produces and what npm uses for package.json. Four spaces is common in Python projects, since json.dumps(data, indent=4) appears in many examples. Tabs keep files smaller and let each reader choose how wide an indent looks.
If your project has a formatter such as Prettier or an .editorconfig file, match it, so formatted JSON doesn't create noise in code reviews. For data that is sent over the network rather than read by people, use Minify to remove whitespace altogether.