JSON Formatter & Validator
Beautify, minify and validate JSON with syntax highlighting.
About the JSON Formatter & Validator
The JSON Formatter & Validator takes any JSON string — minified, malformed, or inconsistently indented — and produces clean, properly indented output while validating the syntax. If your JSON is invalid, the tool reports the exact error position with surrounding context so you can find the bug quickly. If it is valid, you get a beautified version, a minified version, byte size, and a copy button for either.
JSON (JavaScript Object Notation) is the de facto data interchange format for the modern web, replacing XML in most APIs. It is human-readable, lightweight, and supported by every programming language. But JSON has strict syntax rules that trip up even experienced developers: keys must be in double quotes (not single), trailing commas are forbidden, strings cannot contain literal newlines, and comments are not allowed at all. A single mistake breaks the entire document.
This tool catches those mistakes and shows you exactly where they are. Paste a response from an API, a config file, or a request body you are debugging, and you will immediately see whether it parses and how it looks when properly formatted. The validation runs entirely in your browser, so you can safely paste tokens, credentials, or test data without leaking them to a server.
How It Works
The tool uses JavaScript's built-in JSON.parse() to validate the input. This is the same parser that browsers use natively, so the validation matches real-world behavior exactly. If parsing fails, the resulting SyntaxError contains a message like “Unexpected token in JSON at position 42,” and the tool extracts the position number to show you the surrounding context (20 characters before and after the error).
If parsing succeeds, the tool re-serializes the parsed object using JSON.stringify(obj, null, indent) with your chosen indentation (2 spaces, 4 spaces, or a tab character). This round-trip through parse and stringify normalizes the formatting: trailing whitespace is removed, keys are sorted (in V8, the order matches insertion order for string keys), and string escaping is standardized.
For minification, JSON.stringify(obj) without an indent argument produces a single-line output with no unnecessary whitespace. The byte size is computed using the Blob API (new Blob([out]).size), which counts UTF-8 bytes — the size that matters when transmitting JSON over HTTP or storing it in a database.
Worked Examples
The default input is a small JSON object representing a person. Clicking Format with 2-space indentation produces a beautified version with each key on its own line, nested objects indented, and the array elements on separate lines. The output size will be slightly larger than the input (because of the added whitespace), but the byte count over the wire when minified is smaller than the original if the original had extra whitespace.
If you introduce a common error like a trailing comma ({"a": 1,}) and click Format, the tool reports “Unexpected token }” with the position and context. You can then click into your input at that position and fix it. Other common errors caught this way: single-quoted keys ({'a': 1}), unquoted strings ({a: 1}), literal tabs inside strings, and comments (// comment or /* comment */).
For an API response you are debugging, paste the raw response body and click Format. If it parses, you see the structure clearly. If it does not parse (e.g., the server returned an HTML error page instead of JSON), the error message will indicate the problem (typically “Unexpected token <” at position 0, indicating HTML rather than JSON).
When to Use This Tool
- Debugging malformed JSON in API responses or request bodies.
- Beautifying minified JSON for human reading during code review.
- Validating JSON config files (package.json, tsconfig.json, .eslintrc) before saving.
- Comparing JSON output sizes (formatted vs. minified) when optimizing payload size.
- Inspecting JWT payloads (after base64-decoding the body, paste here to see the JSON structure).
- Normalizing inconsistent JSON formatting before committing to version control.
- Teaching JSON syntax by demonstrating how parse errors map to specific characters.
Limitations & Disclaimer
This tool uses JSON.parse and JSON.stringify, which follow strict JSON syntax (no comments, no trailing commas, double-quoted keys only). It will reject JSON5, JSONC, HJSON, and other JSON variants. Error positions may be slightly off in inputs with multi-byte characters because JSON.parse reports positions in UTF-16 code units, not characters. The tool does not perform schema validation (use JSON Schema for that) and does not preserve key order across all browsers (V8 preserves insertion order for string keys; other engines may differ). Circular references in objects will cause JSON.stringify to throw. See our disclaimer for full terms.
Frequently Asked Questions
Why are single quotes not allowed in JSON?
JSON is a subset of JavaScript object literal syntax, but it is stricter. Douglas Crockford designed it to require double-quoted strings and keys to keep parsing simple and unambiguous. Single quotes work in JavaScript but not in JSON. Most JSON parsers (including <code>JSON.parse</code>) reject them.
Why are trailing commas forbidden?
Trailing commas were a source of cross-browser inconsistency in early JavaScript. JSON disallows them entirely to keep the format strict and predictable. If you have a trailing comma in your JSON, the parser will report an error at the closing brace or bracket.
Can I add comments to JSON?
Standard JSON does not support comments. If you need comments, use JSONC (JSON with Comments, used in VS Code's settings.json), JSON5, or a YAML config file. For data interchange, comments should be avoided because they will be stripped by parsers.
What is the difference between JSON and a JavaScript object literal?
JSON is a string format (a serialization). A JavaScript object literal is a code construct that creates an in-memory object. JSON requires double-quoted keys and string values, forbids trailing commas, and does not allow functions or undefined. Object literals can use unquoted keys, single quotes, and even computed property names.
How does the byte counter work?
The tool creates a <code>Blob</code> from the output string and reads its <code>size</code> property. Blob uses UTF-8 encoding, so the byte count reflects the actual transmission size over HTTP. This is more accurate than <code>string.length</code>, which counts UTF-16 code units and can differ for text containing emoji or non-ASCII characters.
Is my JSON uploaded anywhere?
No. Parsing and formatting happen entirely in your browser using JavaScript's native <code>JSON.parse</code> and <code>JSON.stringify</code>. Your JSON — including any tokens, credentials, or test data — never leaves your device.
Last updated: July 21, 2026 · Author: HT99 Tools Editorial Team · Reviewed by: HT99 Tools Editorial Team