JSON Formatter — Format, Validate, Minify and View JSON
Our free JSON formatter gives you four tools in one: prettify messy JSON with proper indentation and syntax highlighting, validate JSON and pinpoint errors by line number, minify JSON to the smallest possible size, or sort all object keys alphabetically. Switch to tree view for an interactive collapsible explorer. All processing runs locally in your browser — no JSON data leaves your machine.
How to Format JSON
Prettify Minified or Compact JSON
Paste any valid JSON into the left panel — minified, compact, or poorly formatted. Click Format to instantly produce clean, indented output with syntax highlighting. Choose 2 spaces, 4 spaces, or tab indentation based on your project's style guide.
Validate and Debug Invalid JSON
Paste JSON that may be invalid into the left panel and click Validate. If the JSON is invalid, the tool shows the exact error message from the JSON parser along with the line and column number where the problem was detected. Common issues include trailing commas, unquoted keys, single-quoted strings, and missing closing brackets.
JSON Syntax Rules
JSON has strict syntax rules. Here are the most common sources of JSON errors:
| Rule | Valid JSON | Invalid JSON | Common Mistake |
|---|---|---|---|
| String quotes | "key": "value" | 'key': 'value' | Using single quotes instead of double quotes |
| Trailing commas | {"a":1,"b":2} | {"a":1,"b":2,} | Extra comma after last item |
| Keys must be strings | {"name":"John"} | {name:"John"} | Unquoted keys (valid JS but not JSON) |
| No comments | {"key":"value"} | {"key":"value"} // comment | Comments are not valid in JSON |
| Boolean values | true, false | True, False, TRUE | Booleans must be lowercase |
| Null value | null | NULL, None, nil | Null must be lowercase |
| Numbers | 1, 1.5, -1 | 1., 01, NaN | No trailing decimal, no leading zeros |
JSON Data Types
| Type | Example | Notes |
|---|---|---|
| String | "Hello World" | Must use double quotes |
| Number | 42, 3.14, -7 | Integer or floating point |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only |
| Array | [1, 2, 3] | Ordered list of values |
| Object | {"key":"val"} | Unordered key-value pairs |
| Nested | {"a":{"b":1}} | Objects and arrays can nest |
JSON Formatting vs Minifying — When to Use Each
When to Format JSON
Use formatted (prettified) JSON when you are reading, writing, debugging, or reviewing JSON in development. Formatted JSON is easier to read and navigate, especially for deeply nested structures. Configuration files, API documentation examples, and code review contexts all benefit from well-formatted JSON.
When to Minify JSON
Use minified JSON in production environments where JSON is transmitted over a network. Removing whitespace reduces file size by 15–30% for typical API responses, reducing bandwidth usage and improving response times. Most web servers and CDNs also support gzip compression which further reduces JSON transfer size.
JSON vs Other Data Formats
| Format | Readability | Size | Comments | Schema | Best For |
|---|---|---|---|---|---|
| JSON | Good | Small | No | Optional (JSON Schema) | APIs, web apps, config |
| XML | Verbose | Large | Yes | Yes (XSD, DTD) | Enterprise, document markup |
| YAML | Excellent | Smallest | Yes | Optional | Config files, DevOps |
| TOML | Good | Small | Yes | No | Config files (Rust, Python) |
| CSV | Poor | Smallest | No | No | Tabular data, spreadsheets |
| MessagePack | None (binary) | Smallest | No | No | High-performance binary APIs |
Common JSON Use Cases
REST API Responses
JSON is the de facto standard format for REST API responses. When you call an API endpoint, the server typically returns data as a JSON object or array. The JSON formatter is useful for inspecting raw API responses from tools like Postman, curl, or browser developer tools.
Configuration Files
Many applications and tools use JSON for configuration files — package.json in Node.js, tsconfig.json in TypeScript, .eslintrc in ESLint, and settings.json in VS Code. Well-formatted JSON configuration files are easier to maintain and review in version control.
Data Storage and Exchange
NoSQL databases like MongoDB and Firestore store data in JSON-like document formats. JSON is also used for importing and exporting data between systems, as a serialization format for caching, and for storing structured data in localStorage or database text fields.
Frequently Asked Questions
What causes "Unexpected token" errors in JSON?
"Unexpected token" errors typically mean the JSON parser encountered a character it did not expect. Common causes include trailing commas after the last element, single-quoted strings instead of double-quoted, JavaScript-style comments, unquoted object keys, or a non-JSON value like undefined or NaN.
Can JSON have comments?
Standard JSON (RFC 8259) does not support comments. If you need comments in a JSON-like format, consider JSONC (JSON with Comments, used by VS Code) or JSON5, which both support // and /* */ comments but require special parsers. Standard JSON.parse() will reject any input containing comments.
What is the maximum size of a JSON file?
There is no formal size limit for JSON files. Practical limits depend on the environment: browser JavaScript engines can handle JSON files of several hundred megabytes, but parsing very large files may be slow. For large datasets, consider streaming JSON parsers or formats designed for large data like JSON Lines (JSONL).
How do I sort JSON keys alphabetically?
Paste your JSON into the left panel and click Sort Keys. The formatter will recursively sort all object keys at every nesting level in alphabetical order. This is useful for normalizing JSON for diffing, version control, or comparing two JSON objects.
Is JSON case sensitive?
Yes. JSON keys and string values are case-sensitive. "Name" and "name" are different keys. The keywords true, false, and null must be lowercase — True, False, and NULL are invalid JSON.