JSON Formatter
Paste JSON to format it with 2 spaces, 4 spaces or tabs, minify it or sort its keys. A syntax error is reported with its line, column and a caret under it. How it works
Use the JSON Formatter
{
"dealership": {
"name": "AutoWorld",
"established": 1995,
"inventory": [
{
"id": "C001",
"make": "Tesla",
"model": "Model 3",
"year": 2023,
"features": {
"autopilot": true,
"battery": "Long Range"
},
"price": 45990
},
{
"id": "C002",
"make": "Ford",
"model": "Mustang",
"year": 1967,
"isVintage": true,
"specs": {
"engine": "V8",
"horsepower": 335
},
"price": 55000
}
],
"location": {
"city": "Detroit",
"zip": "48201"
}
}
}About the JSON Formatter
JSON does not allow trailing commas, comments, single quotes or unquoted keys, so {"a": 1,} is a syntax error. This JSON formatter reports the first error with its line and column and a caret under the spot. Valid JSON is formatted with 2 spaces, 4 spaces or tabs, minified, or printed with its keys sorted.
Common JSON syntax errors and what the formatter reports
| Mistake | Input | Reported at | Message in Chrome and Edge |
|---|---|---|---|
| Trailing comma in an object | {"a": 1,} | Line 1, column 9 | Expected double-quoted property name |
| Trailing comma in an array | [1, 2,] | Line 1, column 7 | Unexpected token ']', "[1, 2,]" is not valid JSON |
| Single quotes | {'a': 1} | Line 1, column 2 | Expected property name or '}' |
| Unquoted key | {a: 1} | Line 1, column 2 | Expected property name or '}' |
| Comment | {"a": 1, /* id */ "b": 2} | Line 1, column 10 | Expected double-quoted property name |
| Missing comma | {"a": 1 "b": 2} | Line 1, column 9 | Expected ',' or '}' after property value |
| Missing colon | {"a" 1} | Line 1, column 6 | Expected ':' after property name |
| Leading zero | {"a": 01} | Line 1, column 8 | Unexpected number |
| NaN as a value | {"a": NaN} | Line 1, column 7 | Unexpected token 'N', "{"a": NaN}" is not valid JSON |
| Missing closing brace | {"a": 1 | Line 1, column 8 | Expected ',' or '}' after property value |
The line and column come from the formatter’s own scan of the text and do not depend on the browser. The message is the browser’s: Firefox and Safari word it differently.
One document after each option
| Option | Lines | Characters |
|---|---|---|
| Minify | 1 | 58 |
| Format, 2 spaces | 9 | 88 |
| Format, 4 spaces | 9 | 106 |
| Format, tabs | 9 | 79 |
Input: { "name": "Ada", "tags": ["math", "code"], "active": true, "id": 7 }, which is 68 characters as typed.
How to use this tool
- Paste JSON into the Input JSON box, or press Open .json file to load a .json or .txt file of up to 5,000,000 bytes, which is formatted at once. A paste into an empty box, or over a full selection, is formatted at once; a paste into the middle of existing text is inserted as usual and the output is marked as out of date. Typed changes are checked after a short pause and marked Valid or Invalid.
- Choose the indent (2 spaces, 4 spaces or tabs) and tick Sort keys if you want every object’s keys sorted (by character code, so capitals before lowercase and number-like keys first), then press Format or Minify.
- Read the output as Raw text or as a Tree, search it, copy it, or download it as formatted.json or minified.json.
Frequently asked questions
- Why does JSON give an error for a trailing comma?
- The JSON grammar (RFC 8259) allows a comma only between two values, never after the last one. JavaScript object literals accept it; JSON does not. Delete the comma before the closing } or ]. The error points at the bracket after the comma, because that is where the parser expected another value.
- Can JSON have comments?
- No. RFC 8259 defines no comment syntax, so // and /* */ are reported as syntax errors. Remove the comment, or keep the note as an ordinary string value.
- How do I minify JSON?
- Paste it and press Minify. All whitespace between values is removed and nothing else changes. The sample document on the page is 650 characters formatted and 368 minified.
- Why did a number change after formatting?
- JavaScript numbers hold whole numbers exactly only up to 9,007,199,254,740,991 (2^53 − 1), and about 17 significant digits in all. 12345678901234567890 comes back as 12345678901234567000, and 1e400 is too large for a JavaScript number and becomes null. The formatter shows a warning with the numbers it happened to. To keep every digit of an ID, store it as a string.
- What happens to duplicate keys?
- Only the last value is kept, and the formatter warns you and names the duplicated keys with their lines. RFC 8259 says names in an object should be unique and notes that parsers handle duplicates differently.
- Is my JSON uploaded?
- No. Pasted JSON and opened files are parsed and formatted in your browser, in a background worker when the document is over 50,000 characters, and the tool makes no network request.
Related Tools
View all toolsJSON Path Query Tool
Test a JSONPath expression on your JSON and see the match count, each matching value and its path. Filters such as ?(@.price < 10) work. Up to 100 KB.
Base64 Converter
Encode text to Base64 or decode Base64 to text. UTF-8, standard and URL-safe alphabets, optional padding on decode, up to 250,000 characters.
URL Encoder/Decoder
Percent-encode or decode text as you type: one value with encodeURIComponent or a whole URL with encodeURI, and an option to read + as a space.
UUID Generator
Generate 1 to 1,000 random v4 UUIDs, or time-based v1, or name-based v5 and v3 from a namespace and a name, and copy them. Repeats of v4 are very unlikely.
ULID Generator
Generate 1 to 500 ULIDs, 26-character IDs that sort by creation time, in upper or lower case, and decode any ULID to the date it was made.
HTML Entity Encoder
Encode text to HTML entities (& < > " ') or decode any of the 2,231 named references in the HTML standard and numeric ones such as é.