JSON Formatter — Tree View, Sort Keys, Line & Column Errors
JSON Formatter validates, pretty-prints, and minifies JSON entirely in your browser. Switch to a collapsible tree, sort object keys, and download the result as a .json file. When JSON is invalid, the error shows the exact line and column — not just a character position. Nothing leaves your device.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. It uses key-value pairs with double-quoted strings, supports nested objects and arrays, and is language-independent. See: RFC 8259.
Why Use This Tool
- Debug API responses — Pretty-print minified JSON or inspect it as a tree. Decode JWT tokens →
- Validate config files — Check package.json, tsconfig, or any JSON config before committing.
- Minify for production — Remove whitespace to shrink payload size by 20–30%.
- Find syntax errors — See the failing line and column for trailing commas, unquoted keys, or single quotes.
- Prepare test fixtures — Format, sort keys, and download sample data. Edit JSON with syntax highlighting →
Tips
- Use Format for debugging and Minify for production payloads.
- Tree view is for inspection; download the formatted or minified text when you need a file.
- Sort keys before diffing two JSON documents so key order noise disappears.
- For syntax highlighting while you type, use the JSON Editor.
How to Use the JSON Formatter
Paste your JSON
Copy JSON from your API, config file, or clipboard and paste it into the input panel.
Choose Format, Minify, or Validate
Format pretty-prints with 2-space indent. Minify removes whitespace. Validate checks syntax only.
Sort, inspect, download
Turn on Sort keys, switch to Tree to expand or collapse nodes, then Copy or Download a .json file.
Fix errors by line and column
Invalid JSON reports line and column so you can jump to the break instead of counting characters.
Worked Examples
Format minified JSON
{"name":"Alice","age":30,"active":true}{
"name": "Alice",
"age": 30,
"active": true
}Minify formatted JSON
{
"users": [
{ "id": 1, "name": "Bob" }
]
}{"users":[{"id":1,"name":"Bob"}]}Minified output is 20–30% smaller for typical payloads.
Sort keys
{"z":1,"a":{"d":2,"c":1}}{
"a": {
"c": 1,
"d": 2
},
"z": 1
}Nested object keys are sorted; array order is unchanged.
Unicode and emoji
{"greeting":"नमस्ते","emoji":"👋"}{
"greeting": "नमस्ते",
"emoji": "👋"
}Unicode characters are preserved correctly.
Common Errors & How to Fix Them
| Error Message | Cause | Fix |
|---|---|---|
Invalid JSON at line 1, column 43: Unexpected token } | Trailing comma after the last property | Remove the comma before the closing brace or bracket. |
Invalid JSON at line 1, column 2: Expected property name or '}' | Unquoted key or single-quoted key | Wrap all keys in double quotes: "key" not key or 'key'. |
Invalid JSON at line 1, column 16: Unexpected token u | Using undefined as a value | JSON does not support undefined. Use null instead. |
Invalid JSON at line 1, column 11: Unexpected token / | Comment in JSON (// or /* */) | Standard JSON does not allow comments. Use JSON5 or JSONC for config files. |
Invalid JSON at line 1, column 9: Unexpected token ' | String wrapped in single quotes | Use double quotes for all strings in JSON. |
Format vs Minify
| Feature | Format | Minify |
|---|---|---|
| Whitespace | Adds indentation & newlines | Removes all whitespace |
| Readability | Human-readable | Machine-optimized |
| File size | Larger (20–30%) | Smaller |
| Use case | Debugging, config files | API payloads, storage |
| Data preserved | Yes, identical | Yes, identical |
Frequently Asked Questions
How do I format JSON online?
Paste JSON into the input panel and click Format. The tool adds indentation and newlines in your browser — nothing is uploaded to a server.
Can I inspect JSON as a tree?
Yes. Switch the view to Tree to expand and collapse objects and arrays. Expand all and Collapse all control the whole document.
Does Sort keys change my data?
Only key order on objects. Nested objects are sorted too. Array item order is left as-is, and values are unchanged.
Why is my JSON invalid?
Common causes include trailing commas, single-quoted strings, unquoted keys, comments, or using undefined. The error message shows the line and column.
What does "Unexpected token" mean in JSON?
The parser found a character it did not expect. Check for missing quotes, extra commas, or comments. The reported line and column point at the first problem.
Does this JSON formatter upload my data?
No. Formatting, validation, the tree, and downloads all run locally with JSON.parse. Your data never leaves the device.
Does minifying JSON lose any data?
No. Minify only removes insignificant whitespace. JSON.parse returns the same value from formatted and minified text.
Can JSON have comments?
Standard JSON (RFC 8259) does not allow comments or trailing commas. If you need comments in config files, use JSON5, JSONC, or YAML instead.