JSON Formatter & Validator
Beautify, minify, and validate JSON per RFC 8259. Runs entirely in browser.
About the JSON Formatter & Validator
The JSON Formatter & Validator on HT99 Tools parses any JSON string against RFC 8259 and either re-emits it pretty-printed (with stable indentation) or minified for transport. Paste a 4 KB Stripe webhook body, a GitHub REST API response, or a 500-line tsconfig.json, and the tool tells you in milliseconds whether the document is well-formed and where the parser stopped if it is not.
JSON became the de-facto wire format for the web because its grammar is tiny: six structural characters ({ } [ ] : ,), three literals (true, false, null), double-quoted strings, and numbers. That same minimalism is what makes hand-editing error-prone. A single trailing comma, a curly quote ” pasted from a Word document, or an unquoted key will cause JSON.parse to throw. This tool surfaces the byte offset of the failure so you can fix the typo instead of squinting at a wall of text.
Two output modes cover the two situations developers actually hit. Pretty-print with 2 or 4 spaces for reading and debugging; minify for shipping. Minified JSON is typically 15–35% smaller than pretty-printed output, which matters when an API response is gzipped 50,000 times a minute.
The tool is also a teaching aid. If you are new to JSON, paste a sample, format it, and observe how the parser groups keys and arrays. If you are debugging a webhook, paste the body, format it, and scan the output for the field your code expects. The byte-offset error context makes the tool useful as a JSON linter — you can find a missing comma in a 4 KB payload in seconds rather than minutes.
The tool is also a teaching aid. If you are new to JSON, paste a sample, format it, and observe how the parser groups keys and arrays. If you are debugging a webhook, paste the body, format it, and scan the output for the field your code expects. The byte-offset error context makes the tool useful as a JSON linter — you can find a missing comma in a 4 KB payload in seconds rather than minutes.
How It Works
The formatter calls the browser's native JSON.parse(text), which implements the RFC 8259 state machine. Parsing is strict: keys must be double-quoted, strings cannot contain literal tabs or newlines (they must be escaped as \t and \n), trailing commas are illegal, and undefined, NaN, and Infinity are not allowed as literals.
On success the parsed value is fed to JSON.stringify(value, null, indent). When indent is a positive integer the result is multi-line with that many spaces per level; when it is '\t' the result uses tabs; when it is 0 the output is minified with no whitespace between tokens. RFC 8259 §6 requires JSON text to be encoded in UTF-8 and forbids a BOM; the browser handles this for us when reading the textarea value.
When parsing fails, the thrown SyntaxError carries a message of the form Unexpected token X in JSON at position N. The tool extracts N, slices 25 characters on either side, and highlights the offending byte with a <mark> element. That visual is the difference between a five-second fix and a five-minute hunt.
Worked Examples
The default input is a single-line Stripe-style charge object of 168 characters. With 2-space indentation it expands to 13 lines and roughly 290 characters; the nested metadata object indents four spaces deep so the email field is visually distinct from the top-level fields. The Delta row reports the size change as a percentage so you can see at a glance whether you saved or lost bytes.
Flip on the Minify option and the same input collapses to {"id":"ch_3OqWxY2eZvKYlo2C","object":"charge","amount":4999,"currency":"usd","paid":true,"refunded":false,"metadata":{"order_id":"ORD-7732","customer_email":"ada@example.com"}} — 168 characters with no whitespace, ready for an HTTP body.
If you delete the closing } on metadata, the tool reports Expected property name or '}' in JSON at position 142 and shows the surrounding context with the cursor position highlighted, so you can see you closed the charge object one level too early.
When to Use This Tool
- Pretty-printing a minified REST API response body so you can read it during debugging.
- Minifying
package-lock.jsonbefore committing to reduce diff noise (some teams keep the file minified on purpose). - Validating a hand-written
manifest.jsonfor a browser extension before packaging. - Detecting where a copy-pasted JSON snippet broke (the position highlight shows the byte offset).
- Normalizing indentation style: convert a 4-space file to 2-space, or vice versa, for a consistent codebase.
- Verifying that a webhook payload you are about to log is parseable before you write it to disk.
- Comparing byte counts before and after minification to estimate bandwidth savings on an API endpoint.
Limitations & Disclaimer
This tool implements RFC 8259 only. It does not accept JSONC (JSON with comments), JSON5 (single quotes, trailing commas, unquoted keys, Infinity), HJSON, or YAML — paste any of those and parsing will fail. The tool does not validate JSON Schema constraints, resolve $ref references, or convert between JSON and XML. Inputs above roughly 10 MB will freeze the tab for several seconds during the synchronous parse. See our disclaimer for the full terms of use.
Frequently Asked Questions
Why does JSON.parse reject trailing commas?
RFC 8259 §13 explicitly lists the five tokens that may follow a value: comma, <code>}</code>, <code>]</code>, end-of-input, or whitespace. A trailing comma is followed by <code>}</code> or <code>]</code>, which is legal in JavaScript object literals but not in JSON. Crockford kept JSON strict so parsers could be tiny and unambiguous.
Are single-quoted strings valid JSON?
No. RFC 8259 §7 defines a string as <code>quotation-mark *char quotation-mark</code>, and the spec defines <code>quotation-mark</code> as the single byte <code>0x22</code> (the ASCII double quote <code>"</code>). Single quotes are an ES5 object-literal extension and will throw a parse error.
What is the largest JSON this tool will handle?
Practically, up to a few megabytes before the synchronous <code>JSON.parse</code> call starts blocking the UI thread noticeably. For 100 MB+ files use a streaming parser such as <code>oboe.js</code>, <code>JSONStream</code>, or Python's <code>ijson</code> library, which yield objects incrementally instead of loading the entire document into memory.
Does the tool preserve key order?
Yes — <code>JSON.stringify</code> iterates object keys in insertion order, as standardised by ES2015 §9.1.12. Be aware that RFC 8259 §4 says objects are ‘unordered’ semantically, so any consumer that depends on key order is relying on implementation-specific behaviour.
Does the tool validate against a JSON Schema?
No. This tool checks syntactic validity (is it parseable JSON?) only. For semantic validation (required fields, type constraints, value ranges) you need a JSON Schema validator like <code>ajv</code> for JavaScript or <code>jsonschema</code> for Python.
Is my JSON sent to your server?
No. Parsing and re-serialisation run entirely in the browser tab. API keys, customer emails, and access tokens you paste here never leave your device.
Last updated: September 9, 2026 · Author: HT99 Tools Editorial Team