JSON Formatter & Validator
Format, validate, and minify JSON in your browser. Choose 2-space, 4-space, or tab indentation. No upload required: all processing stays in your browser.
Paste JSON to pretty-print it with 2-space, 4-space, or tab indentation, or minify it to a single line. Invalid JSON shows the exact parser error and character position.
No upload required. All formatting, validation, and minification runs in your browser. Safe for API responses containing tokens, user data, or production records.
What Is JSON and Why Format It?
JSON (JavaScript Object Notation) is the common data format for web APIs. It is human-readable in theory, but minified JSON from an API response can be a wall of brackets, commas, and nested objects. Formatting makes that structure visible.
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.
The formatter uses the browser's JSON.parse() and JSON.stringify() functions on the page. Paste JSON in, format or minify it, then copy the result. That local workflow is useful when you are debugging API responses that contain auth tokens, user data, or production database records.
Pretty-Printing and Indentation Options
Pretty-printing converts compact, hard-to-read JSON into an indented, multi-line layout where each key-value pair sits on its own line and nested objects are visually separated. The tool offers three indent styles so you can match your team's convention.
2 spaces
The default and the most widely used style in web development. Compact enough that deeply nested JSON remains visible without horizontal scrolling. Matches the Prettier and ESLint defaults used by most JavaScript projects.
4 spaces
Common in Python (json.dumps with indent=4), Java, and C# projects. Gives more visual breathing room between levels. Produces slightly larger files than 2-space output, but the difference disappears when gzip is applied.
Tab
One tab character per indent level. Preferred in projects where developers set their own tab-width in their editor, since each person sees their preferred width automatically. In code, pass '\t' as the third argument to JSON.stringify().
Programmatic equivalent: JSON.stringify(obj, null, 2) gives 2-space output, JSON.stringify(obj, null, 4) gives 4-space output, and JSON.stringify(obj, null, '\t') gives tab output. JSON.stringify(obj) with no third argument produces minified output.
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 is 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 typically minifies to around 6 KB, a saving that compounds at scale 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
Choose your indent style: 2 spaces, 4 spaces, or tab
Click Format to pretty-print or Minify to compress
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?
What does pretty-print mean in JSON?
Is my JSON sent to a server?
What does 'Unexpected token' mean in a JSON error?
How do I find the exact position of a JSON error?
Can this tool fix broken JSON?
What's the difference between formatting and minifying JSON?
How much does minifying JSON reduce file size?
Why do JSON keys need double quotes?
Can JSON have comments?
What's the maximum JSON size this can handle?
Why is a trailing comma invalid in JSON?
How do I validate JSON in JavaScript?
What's the difference between JSON and a JavaScript object?
How do I format JSON with 4-space or tab indentation?
How do I minify JSON for production?
Should I use JSON or YAML for configuration files?
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.