JSON Formatter & Validator
Format, validate and minify JSON in your browser. Nothing is uploaded, so it is safe for internal API payloads. Free.
Scan to open on your phone
Point your phone camera at the code to open this tool.
Paste JSON to validate it, indent it for reading, or strip it down to a single line. The parser tells you the exact position of a syntax error instead of just saying "invalid", and because everything runs in your browser you can safely paste internal API payloads and customer records.
What a JSON formatter actually does
A formatter does not understand your data. It parses the text into a tree, then prints that tree back out with the whitespace you asked for. That is the whole mechanism, and it explains every behaviour on this page — including the ones that surprise people.
Beautifying adds indentation and line breaks so a nested structure becomes readable. Minifying removes every byte of whitespace that the specification allows, which is what you want before sending a payload over the wire or pasting it into a config field.
Because the round trip goes through a parse, the output is not guaranteed to be character-for-character identical to the input. Whitespace is normalised, and a small number of number formats are rewritten. The next two sections cover exactly which ones.
The five things that are valid JavaScript but invalid JSON
Almost every "invalid JSON" a developer hits is one of five habits carried over from writing JavaScript object literals. JSON is a much smaller language than JavaScript, and it deliberately has no room for any of them.
Comments. Neither // nor /* */ exists in JSON. If you want to annotate a config file, use JSON5, JSONC or YAML — the JSON specification has no comment syntax and no plans to add one.
Trailing commas. {"a":1,} is a syntax error. JavaScript allows the trailing comma, JSON does not.
Single quotes. Property names and string values must use double quotes. {'a':1} fails immediately.
Unquoted keys. {a:1} is invalid; {"a":1} is valid. This is the single most common cause of a failed paste from a JavaScript console.
Bare undefined and functions. JSON has no undefined, no NaN, no Infinity, no functions and no dates. A date has to travel as a string or a number, and undefined has to be omitted or turned into null.
The parser reports the position of the first failure, so the error message points you at the character rather than the whole document. For a large payload that is the difference between a one-second fix and a hunt.
How to format and validate JSON
- Paste your JSONThe result appears as you type, and any syntax error is reported with its position.
- Choose beautify or minifyBeautify indents the structure for reading; minify removes every optional space for sending.
- Pick an indent widthTwo spaces is the JavaScript convention, four is the Java and .NET convention, and a tab is what many Go and PHP projects standardise on.
- Fix the reported position and re-pasteThe error names the character position, so a trailing comma or an unquoted key takes seconds to correct.
Worked examples
- {"name":"Ada","roles":["admin","editor"],"active":true}
- Indented over five lines with two-space indentationThe default case: nested arrays and objects each get their own line.
- {"a":1,"a":2}
- {"a": 2}Duplicate keys are legal JSON. The parser keeps the last one and discards the earlier value without warning.
- {"a":1,}
- Invalid JSON — Expected double-quoted property name in JSON at position 7A trailing comma. The reported position is exactly where the parser gave up.
- "hello"
- "hello"A top-level string is valid JSON. Only JavaScript object literals need the surrounding braces.
- {"n":9007199254740993}
- {"n": 9007199254740992}The value changed. See the precision section below — this is the one case where a formatter silently alters your data.
The one case where a formatter changes your data
JSON numbers have no size limit in the specification, but the JavaScript engine that parses them does. Every number becomes a 64-bit floating-point value, and above 2^53 − 1 — that is 9,007,199,254,740,991 — integers can no longer be represented exactly.
In practice this bites on identifiers, not on quantities. A 19-digit database ID, a Twitter or Discord snowflake, a large order number, a payment amount in the smallest currency unit — anything that is really a string of digits stored as a number will be rounded the moment it is parsed, and the formatter will print the rounded value back at you.
The value 9007199254740993 in the examples above comes back as 9007199254740992. Nothing warns you, because from the parser's point of view nothing went wrong.
The fix is at the source, not in the formatter: send large identifiers as JSON strings — "id": "9007199254740993" — and parse them into a big-integer type on the receiving end. If you cannot change the producer, treat any 16-digit-or-longer number in a formatted payload as suspect and verify it against the original.
Does formatting preserve key order?
For ordinary objects, yes. The parser keeps insertion order for keys that are not integers, and prints them back in that order, so the structure you paste is the structure you get.
Two exceptions are worth knowing. First, keys that look like array indices — "0", "1", "2" — are treated as integer keys by the JavaScript engine and are always listed in ascending numeric order, ahead of the named keys. Second, the JSON specification itself says an object is an unordered collection, so no downstream system is obliged to keep your order even if this tool does.
If key order matters to a diff, a signature or a hash, do not rely on it. Sort the keys explicitly — there is a separate tool for that — or compare the parsed structures rather than the text.
What this formatter does not do
It does not validate against a schema. It checks that your text is well-formed JSON, which is a syntax question. Whether "age" is supposed to be a number, whether an email address is actually an address, whether a required field is missing — those are schema questions, and they need a JSON Schema validator.
It does not sort, filter, query or diff. Sorting keys, extracting values with a path expression and comparing two payloads are separate tools, deliberately kept separate so that formatting stays a one-step operation you can trust.
It does not repair broken JSON. Some tools guess at missing quotes and trailing commas; guessing silently is worse than failing loudly, because a repaired payload may parse while meaning something different from what you intended.
It is not a JSON editor for enormous files. The parse happens in browser memory, so a hundred-megabyte export will be limited by your device rather than by any server-side quota.
References
Frequently Asked Questions
- Is it safe to paste internal API data here?
- Yes. Formatting runs in JavaScript inside your browser and the JSON is never sent to a server, so confidential payloads stay on your machine.
- What does the validator check?
- It parses your input against the JSON spec and reports the exact problem, such as a trailing comma or an unquoted key.
- Can it minify as well as beautify?
- Yes. Switch the mode to minify to strip all whitespace and shrink the payload.