JSON Formatter & Validator
Free online JSON formatter, validator and beautifier. Paste JSON to format, minify, validate and copy — fast, private, runs in your browser.
What is a JSON formatter?
JSON (JavaScript Object Notation) is the most widely used data interchange format on the modern web. Almost every API, configuration file, and database export uses JSON in some form. But raw JSON — especially when minified or generated by another machine — is notoriously hard to read. A JSON formatter takes a string of compact, escaped, or malformed JSON and produces a clean, indented version that humans can scan, search, and understand.
Why use this tool?
This JSON formatter runs entirely in your browser. Nothing you paste is ever uploaded to a server, logged, or stored. That matters when you're working with API keys, customer records, internal payloads, or anything else that shouldn't leave your machine. It's also fast: pasting a multi-megabyte payload formats in milliseconds, with no round-trip latency.
- Pretty-print compact JSON returned from an API into a readable layout
- Validate that a string is syntactically correct JSON before sending it
- Minify a JSON document to reduce payload size for production
- Copy the formatted result to your clipboard with one click
How to format JSON online
- Paste your JSON into the Input JSON box on the left.
- Click Format (2 sp) for two-space indentation, Format (4 sp) for four, or Minify to strip all whitespace.
- The result appears on the right. Click Copy to put it on your clipboard.
- If your input is invalid, you'll see an inline error message describing where the parser failed — useful for tracking down a missing comma or unbalanced bracket.
Example
Input (compact)
{"name":"alice","roles":["admin","editor"],"active":true}Output (formatted with 2-space indentation)
{
"name": "alice",
"roles": [
"admin",
"editor"
],
"active": true
}Common JSON errors and how to fix them
Almost every "invalid JSON" error a developer hits in real life is one of these six. The strict JSON spec (RFC 8259) is deliberately narrow — most of what looks like JSON in the wild is actually JSON5, JSONC, or JavaScript-object literals, which are NOT the same thing. Here is what the parser rejects and how to fix it.
1. Trailing comma after the last item
JavaScript allows it; JSON does not.
// INVALID
{
"name": "alice",
"role": "admin", ← trailing comma rejected
}
// VALID
{
"name": "alice",
"role": "admin"
}Why: RFC 8259 defines objects and arrays with a grammar that requires a value between every pair of commas. A trailing comma implies a missing value. Many JavaScript developers hit this because their linter allows trailing commas in .js files (and for good reason — they produce cleaner diffs), but JSON.parse is strict.
2. Single quotes instead of double quotes
// INVALID (JS object literal, not JSON)
{
'name': 'alice'
}
// VALID
{
"name": "alice"
}Why: JSON strings must use double quotes. Single quotes are a JavaScript convenience; JSON's grammar does not permit them. Fix: find-replace ' with " — but be careful with strings that contain apostrophes (don't).
3. Unquoted property names
// INVALID
{
name: "alice"
}
// VALID
{
"name": "alice"
}Why: JSON property names must be quoted strings. This trips up JavaScript developers constantly because JS object literals let you omit quotes around valid identifier names. JSON's grammar has no such shortcut — every key is a string, every string needs quotes.
4. Comments
// INVALID (strict JSON has no comments)
{
"name": "alice", // this is rejected
/* or this */
"role": "admin"
}
// VALID
{
"name": "alice",
"role": "admin"
}Why: JSON was designed for data exchange, not human-authored config, so comments were explicitly excluded. If you need comments, use JSONC (JSON with Comments — what VS Code's tsconfig.json uses) or JSON5. Both are dialects — strip comments before passing to any standard JSON parser.
5. undefined, NaN, or Infinity
// INVALID
{
"value": undefined,
"ratio": NaN,
"max": Infinity
}
// VALID (closest equivalents)
{
"value": null,
"ratio": null,
"max": 1e308
}Why: JSON has no syntax for these three JavaScript values.null is the closest JSON equivalent for undefined. For NaN and Infinity, either use null (lose the information) or encode them as strings ("NaN") and decode them downstream. JSON.stringify silently drops undefined properties, converts NaN and Infinity to null — this is a classic source of bugs when serializing ML model output or calculation results.
6. Duplicate keys
// PARSES but ambiguous — the spec says "SHOULD be unique"
{
"name": "alice",
"name": "bob"
}Why: Technically not an error — most parsers keep the last occurrence. But RFC 8259 says names "should be unique", and behavior varies: JSON.parsekeeps the last, Jackson (Java) can be configured to throw, Python's json keeps the last by default. If you see duplicate keys, the producer has a bug — fix it at the source.
Other common gotchas
- Leading zeros on numbers:
{"id": 007}is invalid. JSON numbers cannot have leading zeros unless the whole number is 0. Fix: use a string ("007") if you need the leading zero preserved - Hex or binary literals:
{"color": 0xFF}is invalid. JSON only accepts decimal numbers. Convert to decimal (255) or store as string - Unescaped control characters in strings: a literal tab or newline inside a string field is invalid — they must be escaped as
\tor\n. This bites developers pasting log excerpts into JSON string fields - BOM at the start: a UTF-8 byte-order mark (
\uFEFF) at the start of a file is technically allowed in some parsers but rejected byJSON.parse. Strip it before parsing
Frequently asked questions
Is my JSON sent anywhere?
No. Formatting and validation happen entirely in your browser using the standard JSON.parse and JSON.stringify APIs. No network request is made with your input.
Why does the formatter say my JSON is invalid?
Common causes: trailing commas (not allowed in strict JSON), single quotes instead of double quotes, unquoted property names, comments (also not allowed in strict JSON), or escape sequences that aren't recognized. The error message points at the first invalid character so you can find the problem quickly.
Can I format JSON5 or JSONC?
This tool follows the strict JSON specification (RFC 8259). JSON5, JSONC, and similar dialects allow comments and trailing commas, but most APIs and configuration consumers expect strict JSON. If you need JSON5, format with that dialect's tooling first, then paste the strict-JSON output here.
What's the difference between formatting and validating?
Validation checks whether a string is syntactically valid JSON. Formatting produces a human-readable layout. This tool does both at the same time: a successful format implies the input was valid, and an invalid input shows you exactly what went wrong.
Can I use this for very large files?
Yes. Because everything runs locally, there is no upload size limit other than what your browser can hold in memory. We've tested with files in the tens of megabytes without issue.
Related tools
- Cron ExplainerTranslate cron expressions into plain English and see the next fire times. Free, fast, runs entirely in your browser.
- TimestampConvert between Unix timestamps and human-readable dates. Free online epoch converter — supports seconds, milliseconds and ISO 8601.
- YAML ⇄ JSONConvert between YAML and JSON in both directions. Validates syntax, handles nested structures, runs entirely in your browser.