JSON Formatter & Validator
Format, validate, and minify JSON instantly. Pretty-print with 2 or 4 space indentation. 100% browser-based.
Paste JSON to format with proper indentation or minify to a single line. Invalid JSON shows the exact error.
What Is JSON and Why Format It?
JSON (JavaScript Object Notation) is the lingua franca of the web. Every API you've ever used almost certainly speaks JSON. It's human-readable in theory, but in practice, minified JSON from an API response is a wall of brackets, commas, and nested objects that makes your eyes bleed. That's where formatting comes in.
Pretty-printing JSON adds indentation and line breaks so you can actually see the structure. Nested objects become obvious. Missing commas jump out. A 500-character blob becomes a clear, scannable tree. It's the difference between reading a paragraph with no spaces and reading one with proper formatting.
This tool runs entirely in your browser, your JSON never leaves your device. Paste it in, format or minify, copy the result. No API calls, no data logging, no privacy concerns. That matters when you're debugging API responses that contain auth tokens, user data, or production database records.
JSON Data Types at a Glance
| Type | Example | Rules |
|---|---|---|
| String | "name": "Alice" | Always double-quoted |
| Number | "age": 30 | No quotes, supports decimals and negatives |
| Boolean | "active": true | Lowercase true/false only |
| Null | "deleted": null | Lowercase null (not undefined) |
| Array | "tags": ["a", "b"] | Ordered list, mixed types allowed |
| Object | {"key": "value"} | Unordered key-value pairs |
JSON doesn't support: comments, trailing commas, single quotes, undefined, NaN, Infinity, dates (use ISO 8601 strings), or functions. These are the most common reasons JSON fails to parse.
JSON Error Reference
When JSON.parse() fails, the error message can be cryptic. Search for your error message below to find the cause and fix.
| Error Message | Cause | Fix |
|---|---|---|
| Unexpected token ' | Single quotes around keys or values | Replace all single quotes with double quotes: 'name' → "name" |
| Unexpected end of JSON input | Missing closing bracket, brace, or truncated response | Count opening/closing pairs, every { needs } and every [ needs ] |
| Expected ',' or '}' | Trailing comma after last item in object/array | Remove the comma after the last property: {"a": 1,} → {"a": 1} |
| Unexpected token / | JavaScript-style comments in JSON | Remove all // and /* */ comments, JSON doesn't support them |
| Bad escaped character | Unescaped backslash or quote inside string | Escape special chars: use \\ for backslash, \" for quote in strings |
| Unexpected token u | undefined value (not valid JSON) | Replace undefined with null, JSON only supports null, not undefined |
| Unexpected number / NaN / Infinity | NaN or Infinity in output | NaN and Infinity aren't valid JSON. Convert to null or a string first |
| Unterminated string | String contains unescaped newline | Use \n for newlines inside strings, not actual line breaks |
| Duplicate key | Same key appears twice in an object | Remove the duplicate. Last value wins in most parsers but it's ambiguous |
| json.decoder.JSONDecodeError | Invalid JSON passed to json.loads() | Check for BOM (byte order mark), trailing content, or encoding issues |
| JsonSyntaxException | Malformed JSON string | Validate your JSON first. Check for unquoted keys or JavaScript syntax |
| SyntaxError: JSON.parse | Any invalid JSON passed to JSON.parse() | Wrap in try/catch. Log the raw string to see what's actually being parsed |
| Cannot read property of undefined | Accessing nested property that doesn't exist | Use optional chaining: data?.user?.name instead of data.user.name |
| Maximum call stack size exceeded | Circular reference in JSON.stringify() | Remove circular refs before stringifying, or use a replacer function |
Showing 14 of 14 errors.
HTTP Status Codes (API Quick Reference)
When you're formatting JSON from an API response, the status code tells you what happened before you even look at the body. Search by code number or description.
| Code | Status | Meaning |
|---|---|---|
| 200 | OK | Request succeeded. The response body contains the requested data. |
| 201 | Created | New resource was created successfully. |
| 204 | No Content | Request succeeded but there's no response body. |
| 301 | Moved Permanently | Resource has moved to a new URL permanently. |
| 302 | Found | Resource is temporarily at a different URL. |
| 304 | Not Modified | Cached version is still valid. |
| 400 | Bad Request | The request was malformed or missing required fields. |
| 401 | Unauthorized | Authentication is required or has failed. |
| 403 | Forbidden | You're authenticated but don't have permission. |
| 404 | Not Found | The requested resource doesn't exist. |
| 405 | Method Not Allowed | HTTP method not supported for this endpoint. |
| 409 | Conflict | Request conflicts with current state of the resource. |
| 413 | Payload Too Large | Request body exceeds the server's size limit. |
| 415 | Unsupported Media Type | Content-Type header is wrong. |
| 422 | Unprocessable Entity | JSON is valid but the data doesn't pass validation. |
| 429 | Too Many Requests | Rate limit exceeded. |
| 500 | Internal Server Error | Something broke on the server side. |
| 502 | Bad Gateway | Server got an invalid response from upstream. |
| 503 | Service Unavailable | Server is overloaded or down for maintenance. |
| 504 | Gateway Timeout | Upstream server didn't respond in time. |
Showing 20 of 20 codes.
Format vs Minify: When to Use Each
Format (pretty-print)
Use during development, debugging, code review, and documentation. Readable structure helps you spot issues. Choose 2-space indent for compact output, 4-space for maximum readability, or tab indent if that's your project's standard.
Minify (compact)
Use for production APIs, config files, localStorage, and data transfer. Removes all whitespace to reduce payload size. A 10 KB formatted JSON might minify to 6 KB, a 40% saving that adds up at scale, especially over slow mobile connections.
| Payload Size | Formatted | Minified | Savings |
|---|---|---|---|
| Small API response | 2 KB | 1.2 KB | 40% |
| Product catalogue | 500 KB | 280 KB | 44% |
| GeoJSON dataset | 5 MB | 2.8 MB | 44% |
| + gzip compression | 5 MB → 800 KB | 2.8 MB → 650 KB | 84-87% |
Key insight: Gzip compression (which most servers apply automatically) dramatically reduces size regardless of formatting. The real win from minification is eliminating whitespace before gzip, but the difference is smaller than you'd expect. Format for development, minify for production, and make sure gzip is enabled on your server.
JSON vs Alternatives
| Format | Comments | Readable | Best For |
|---|---|---|---|
| JSON | No | Good (formatted) | APIs, data transfer, configs |
| YAML | Yes | Excellent | Docker, CI/CD, Kubernetes |
| TOML | Yes | Excellent | App config (Cargo, pyproject) |
| JSON5 | Yes | Great | Config files where comments help |
| XML | Yes | Poor (verbose) | Legacy systems, SOAP, SVG |
| Protocol Buffers | Yes (.proto) | No (binary) | High-performance gRPC APIs |
| MessagePack | No | No (binary) | Compact data transfer |
What this means for you: JSON won the API format war because it's native to JavaScript and simple to parse in every language. Use YAML or TOML for config files where you need comments. Use JSON for data exchange. If you need comments in JSON, use JSON5 or JSONC (JSON with Comments, what VS Code uses for settings).
Worked Example: Debugging a Failing API Call
The situation: Dev is building a React app that calls a REST API. The fetch request keeps failing with "SyntaxError: Unexpected token" when calling JSON.parse(). The raw response looks like a wall of text.
Step 1: Copy the raw response
In the browser DevTools Network tab, find the failing request, click the Response tab, and copy the entire response body. It's 2,000 characters of minified JSON, impossible to read.
Step 2: Paste into the formatter
Pasting into this tool immediately shows a validation error: "Unexpected token at position 847." The tool highlights the problem area. It turns out the API returned a 500 error page (HTML, not JSON), the response starts with <!DOCTYPE html>.
Step 3: Check the status code
Back in DevTools: the response status is 500 Internal Server Error. The server crashed and returned an HTML error page instead of JSON. The fix is server-side, the endpoint needs error handling that returns JSON even on failure.
Step 4: Add defensive parsing
In the meantime, wrap the client-side parse in a try/catch: check response.ok before calling response.json(), and handle non-JSON responses gracefully instead of crashing.
JSON Best Practices
Use consistent naming
Pick camelCase or snake_case and stick with it across your entire API. Mixing "firstName" and "last_name" in the same response confuses every developer who touches it.
Dates as ISO 8601 strings
Always use "2026-04-15T14:30:00Z" format. Not timestamps, not "April 15th", not "15/04/2026". ISO 8601 is unambiguous, sortable, and parseable in every language.
Null vs missing keys
Be deliberate: "email": null means "this field exists but has no value." Omitting the key entirely means "this field doesn't apply." Document which approach your API uses.
Always validate on the server
Never trust incoming JSON. Validate types, required fields, and value ranges. A missing field that your code assumes exists will crash at 3am on a Friday.
Common Mistakes
Trailing commas
JavaScript allows trailing commas everywhere, so you forget JSON doesn't. [1, 2, 3,] is valid JS but invalid JSON. Always remove the comma after the last element.
Stringifying twice
Calling JSON.stringify() on a string that's already JSON wraps it in extra quotes and escapes. You get "{\"name\":\"Alice\"}" instead of '{"name":"Alice"}'. Check if the input is already a string before stringifying.
Not checking Content-Type
Your API returns HTML error pages, but your code blindly calls JSON.parse() on every response. Always check that Content-Type is application/json before parsing.
Logging sensitive data
Pretty-printing an API response to console.log in production, including auth tokens, API keys, and user PII. Use environment checks to suppress JSON logging in production.
Huge JSON in localStorage
Storing megabytes of JSON in localStorage (5 MB limit in most browsers). It blocks the main thread during read/write. Use IndexedDB for large datasets, localStorage for small config only.
No error handling for parse
JSON.parse() throws on invalid input. Always wrap it in try/catch. An uncaught parse error can crash your entire app if it's in a request handler or event listener.
Related Tools
CSV to JSON Converter
Convert spreadsheet data to JSON format
JSON to CSV Converter
Export JSON data as CSV for spreadsheets
XML Formatter
Format and validate XML documents
JWT Decoder
Decode and inspect JWT tokens (JSON payload)
Base64 Encoder/Decoder
Encode and decode Base64 strings
SQL Formatter
Pretty-print SQL queries
How to use this tool
Paste your raw JSON into the input area
Click Format to pretty-print or Minify to compress
Copy the result or view syntax-highlighted output
Common uses
- Debugging API responses during development
- Formatting config files for readability
- Minifying JSON payloads to reduce file size
- Validating JSON structure before deployment
Share this tool
Frequently Asked Questions
What does this JSON formatter do?
Is my JSON sent to a server?
Can this tool fix broken JSON?
What's the difference between formatting and minifying JSON?
Why do JSON keys need double quotes?
Can JSON have comments?
What's the maximum JSON size this can handle?
Why does my JSON have trailing comma errors?
How do I validate JSON in JavaScript?
What's the difference between JSON and a JavaScript object?
Can I format JSON with 4 spaces or tabs?
How do I minify JSON for production?
Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.