About the JSON Formatter
Paste JSON into this JSON formatter to pretty-print it, minify it or check that it's valid. If it's broken, you get the line and column of the problem. Big numbers like 12345678901234567890 and duplicate keys stay exactly as you wrote them, because the formatter re-indents your text and never rebuilds it from parsed values.
APIs, log shippers and build tools usually write JSON on one long line, which suits a program and not a person. Formatting adds line breaks and indentation, so you can see where an object ends or spot the field that's missing from a response. Minify goes the other way, for a request body or an environment variable. Both run in your browser.
- Paste your JSON into Input JSON, or click Load sample to try a product record that contains
9007199254740993and59.90. The output refreshes about a quarter of a second after you stop typing. - Check the label above the output. Good input shows Valid JSON and the output size, for example
Valid JSON · 206 B. Broken input shows an Invalid JSON box under the editor with the message, the line and column, and the line itself with a^under the problem. The line number in the editor turns red as well. - Pick Format or Minify. Format uses the Indent menu (2 spaces, 4 spaces or Tab); the menu is grayed out while Minify is on.
- Turn on Sort keys only when you need keys in A to Z order, for example to compare two responses. A note under the switch counts any integers it will round.
- In Code View, click Copy, or Download .json to save
formatted.json(minified.jsonwhen Minify is on). Output longer than 200,000 characters is shown without colors so the page stays responsive. - Open Tree View to browse the structure. Each object and array shows how many keys or items it holds; click one to open or close it, or use Expand all and Collapse all. Levels with more than 500 entries show the first 500 and a Show all link.
- Inside Input JSON, the Tab key indents the selected lines and Shift+Tab removes one level. Press Escape first when you want Tab to move to the next control. Clear empties the editor.
Input{"order":{"id":"A-1042","items":[{"sku":"KB-01","qty":2}],"total":59.90},"customer":{"name":"Aiko Tanaka","city":"Osaka"}}Output{
"order": {
"id": "A-1042",
"items": [
{
"sku": "KB-01",
"qty": 2
}
],
"total": 59.90
},
"customer": {
"name": "Aiko Tanaka",
"city": "Osaka"
}
}Format with Indent set to 2 spaces. 59.90 keeps its trailing zero. Click Minify to get the one-line version back.
Input{
"city": "Lagos",
"country": "NG"
"population": 15388000
}OutputInvalid JSON
Expected "," or "}" after property value, found character "\"" (line 4, column 3)
4 | "population": 15388000
^The comma is missing at the end of line 3, but the parser only notices when the next key starts. When an error points at the start of a line, look at the end of the line above it.
Input{"id": 1850012345678901234, "amount": 1050.00}Output{
"id": 1850012345678901234,
"amount": 1050.00
}JSON.stringify(JSON.parse(text), null, 2) prints 1850012345678901200 and 1050 for the same input. The ID is a different number after that round trip.
Common JSON syntax errors and how to fix them
RFC 8259 allows only objects, arrays, double-quoted strings, numbers, true, false and null, so text that works in a .js file often fails here. Each item shows a small input and the exact message you'll get.
- Trailing comma:
[1, 2,]givesTrailing comma before "]" (line 1, column 7). Delete the comma after the last item. - Single quotes:
{'a': 1}givesExpected a property name in double quotes, found character "'" (JSON strings need double quotes) (line 1, column 2). Use double quotes for keys and strings. - Unquoted keys:
{a: 1}givesExpected a property name in double quotes, found character "a" (line 1, column 2). Quote every key. - Comments:
{"a": 1 // note}givesExpected "," or "}" after property value, found character "/" (line 1, column 9). JSON has no comments, so remove them or move the note into a field. - Values from other languages:
NaN,Infinity,undefined, and Python'sTrueandNoneall fail.{"a": NaN}givesUnknown value "NaN". Text must be in double quotes (only true, false and null have no quotes) (line 1, column 7). Usenull, a string, or lowercasetrueandfalse. For a Python dict, usejson.dumpsinstead ofprint. - Leading zeros and hex:
007givesInvalid number, and0x1Fis rejected too. JSON numbers are decimal only. - Two values in one paste: copying two lines from a JSON Lines (NDJSON) log gives
Unexpected character "{" after the end of the JSON value (line 2, column 1). Format one line at a time, or wrap them in[ ]with a comma between them. - Byte order mark: a file saved as "UTF-8 with BOM" starts with an invisible character, and you get
Unexpected invisible character U+FEFF (line 1, column 1). RFC 8259 says JSON writers must not add a BOM, so save the file as plain UTF-8. - Windows paths:
{"path": "C:\Users"}givesBad escape "\U" in string (line 1, column 13). A backslash starts an escape, so writeC:\\Usersor use forward slashes.
Why many formatters change big numbers
A typical online formatter runs JSON.parse and then JSON.stringify. JSON.parse stores every number as an IEEE 754 double, so the largest integer it holds exactly is 9007199254740991 (2^53 - 1). Larger ones are rounded: 9007199254740993 becomes 9007199254740992. The same round trip turns 59.90 into 59.9 and silently drops the first of two duplicate keys.
That's a real problem for 64-bit database IDs, social media post IDs and payment amounts. RFC 8259 calls only integers from -(2^53 - 1) to 2^53 - 1 safe to exchange, so if you design the API, send bigger IDs as strings.
Other languages differ. Python's json module keeps big integers exact but prints 59.90 as 59.9. PHP's json_decode turns them into floats unless you pass JSON_BIGINT_AS_STRING. jq 1.7 and later keep number literals as written, but arithmetic on them still uses doubles.
Here, Format and Minify work on your original text, so nothing is rounded. Sort keys is the one option that parses the JSON into JavaScript values, and the note under it tells you when that rounds a number.
JSON, JSON5 and JSONC
A file with comments or trailing commas on purpose is usually JSON5 or JSONC; VS Code's settings.json and TypeScript's tsconfig.json are JSONC. Strict JSON parsers, this one included, reject both. For a config format that allows comments, convert the data with JSON to YAML.
Format and validate JSON in code
Each snippet parses the JSON, which throws or returns an error when it's invalid, and prints it with indentation. python3 -m json.tool and PHP's JSON_PRETTY_PRINT use 4 spaces by default. Go's json.Indent works on the raw bytes, so like this page it keeps numbers as written. AI assistants can call the same formatter as format_json and validate_json through the toolo MCP server.
const pretty = JSON.stringify(JSON.parse(text), null, 2);
// JSON.parse throws a SyntaxError for invalid JSONimport json
pretty = json.dumps(json.loads(text), indent=2)python3 -m json.tool --indent 2 data.jsonjq . data.json # pretty-print with 2 spaces
jq -c . data.json # minify
jq -S . data.json # sort keysvar out bytes.Buffer
if err := json.Indent(&out, data, "", " "); err != nil {
return err // not valid JSON
}
// From a Go value instead of raw bytes:
b, err := json.MarshalIndent(v, "", " ")$pretty = json_encode(
json_decode($text, flags: JSON_THROW_ON_ERROR),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);How do I check if my JSON is valid?
Paste it into Input JSON. Valid input shows Valid JSON and the output size. Invalid input shows the error message with its line and column, plus the broken line with a ^ under the first character the parser couldn't accept.
Is a JSON beautifier the same as a JSON formatter?
Yes. Beautify, pretty-print and format all mean adding line breaks and indentation. A validator only checks the syntax. This page does both at once, and Minify removes the whitespace again without changing the data.
How do I format JSON in VS Code?
Open the file and run Format Document: Shift+Alt+F on Windows, Shift+Option+F on macOS, or Ctrl+Shift+I on Linux. For a file with comments, set the language mode to JSON with Comments first, or VS Code reports them as errors.
Does JSON allow comments?
No. JSON has no comment syntax, so // and /* */ cause an error. JSON5 and JSONC allow comments, but they're different formats that many JSON parsers reject.
Can a JSON object have duplicate keys?
RFC 8259 says keys should be unique and warns that programs handle duplicates differently; most keep only the last value. Code View and Tree View keep both copies here so you can find and fix them. Sort keys keeps only the last one.
Is a single value like 42 or "hello" valid JSON?
Yes. RFC 8259 lets a JSON text be any value, not only an object or an array, so 42, "hello", false and null all pass validation.
Is it safe to paste an API response with customer data or tokens?
The JSON is parsed and formatted in your browser and isn't uploaded, so customer records and access tokens in a response stay on your machine. To read the claims inside a token from that response, paste it into the JWT Decoder.