JSON Formatter & Validator
Format, validate, and beautify JSON data
Last updated
How to Use This Tool
Paste your JSON, then format it to make it readable. Copy the formatted output when youβre done.
When Should You Use This Tool?
Use this when youβre debugging APIs, reading minified JSON, or cleaning up JSON before sharing.
Steps
- Paste JSON input.
- Run format/validate.
- Copy the formatted JSON.
See also: Unit Converter, Coin Flip .
What does a JSON formatter and validator do?
A JSON formatter checks that your JSON is valid and prints it again with consistent indentation, so you can read nested objects and arrays at a glance. This tool parses your input with the browser's built-in JSON parser, then writes it back out with 2-space, 4-space or tab indentation (Format JSON) or with every optional space and line break removed (Minify JSON). If the input is not valid JSON, you get the parser's error message, with the line and column where possible, instead of a result, so the same button works as a validator.
How do I format or validate JSON here?
- Paste your JSON into the input box. Leading and trailing whitespace is ignored.
- Choose the Indentation: 2 spaces (the default), 4 spaces or a tab.
- Click Format JSON to pretty print it, or Minify JSON to compress it onto one line.
- If the JSON is invalid, read the error message below the buttons, go to the line and column it names, fix the mistake, and try again. Any earlier result is cleared, so Copy Result never copies stale output.
- Click Copy Result to copy the output.
Everything runs in your browser. Your JSON is not uploaded, which matters when it contains API keys, customer records or internal data.
What is the difference between formatted and minified JSON?
Formatted JSON adds line breaks and indentation for people, while minified JSON removes them to save bytes for machines. The data is identical. Here is one object both ways:
{"id":42,"name":"Ada","tags":["admin","editor"],"address":{"city":"London","zip":"N1"}}
{
"id": 42,
"name": "Ada",
"tags": [
"admin",
"editor"
],
"address": {
"city": "London",
"zip": "N1"
}
}
Use the formatted version when reading API responses, reviewing config files or comparing two payloads in a diff. Use the minified version for request bodies, environment variables or anywhere a single line is required.
How do I know if my JSON is valid?
Your JSON is valid if Format JSON produces output. If it does not, an error message appears below the buttons, explaining what the parser expected and, when the browser reports a position, the line and column of the problem. Here the comma after "Ada" is missing:
{
"id": 42,
"name": "Ada"
"admin": true
}
Invalid JSON at line 4, column 3: Expected ',' or '}' after property value in JSON at position 32
That is Chrome and Edge wording. Firefox words its messages differently but also reports the line and column, while Safari usually names the problem without a location. Lines and columns count from 1, and the character position counts from 0. The mistake is usually at or just before the reported spot: with a missing comma, the parser only complains when it reaches the next key, and with a trailing comma, when it reaches the closing brace after it.
What are the most common JSON syntax errors?
Most invalid JSON comes from copying a JavaScript object or a Python dictionary and treating it as JSON. JSON is stricter: keys and strings need double quotes, and the only literal values are true, false and null.
| Error | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'name': 'Ada'} | {"name": "Ada"} |
| Unquoted keys | {name: "Ada"} | {"name": "Ada"} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Comments | {"a": 1} // note | {"a": 1} |
| Python values | {"ok": True, "x": None} | {"ok": true, "x": null} |
| JavaScript values | {"a": undefined, "b": NaN} | {"a": null, "b": null} |
| Unclosed bracket | [1, 2 | [1, 2] |
| Raw line break in a string | A string split across two lines | "line one\nline two" |
Can formatting change my JSON data?
Formatting keeps your structure and values, but because the tool parses the JSON into JavaScript and serializes it again, a few details can change. These are limits of the JavaScript JSON parser, and most online formatters share them:
- Very large integers lose precision. JavaScript numbers are 64-bit floating point, so integers above 9,007,199,254,740,991 are rounded:
12345678901234567890becomes12345678901234567000. Check 64-bit IDs before you copy the output. - Duplicate keys collapse.
{"a": 1, "a": 2}becomes{"a": 2}, because the last value wins. - Number notation is normalized.
1.0becomes1and1e3becomes1000. - Unicode escapes are decoded.
"Γ©"is printed as"Γ©". - Integer-like keys move first. Keys such as
"1"and"2"are listed before other keys in ascending order. All other keys keep their original order.
How do I format JSON from the command line or in code?
These commands produce the same kind of output as this tool, which is handy for scripts and large files:
# jq (2-space indent by default)
jq . data.json
jq --indent 4 . data.json
jq --tab . data.json
# Python (4-space indent by default)
python -m json.tool --indent 2 data.json
python -m json.tool --tab data.json
// JavaScript
JSON.stringify(JSON.parse(text), null, 2) // 2 spaces
JSON.stringify(JSON.parse(text), null, 4) // 4 spaces
JSON.stringify(JSON.parse(text), null, '\t') // tab
JSON.stringify(JSON.parse(text)) // minified