JSON Formatter & Validator
Format, validate and minify JSON, with exact line-and-column error locations and recursive key sorting. Everything runs in this page — nothing you paste is uploaded anywhere.
Paste or type JSON, then choose an action.
Runs entirely in your browser. Your JSON is never uploaded or sent to a server.
How to use the JSON formatter
- Paste or type your JSON into the input box (a small example is pre-filled).
- Click Format for readable, indented JSON, or Minify for the smallest possible output.
- Pick an indent width (2 spaces, 4 spaces, or a tab) before formatting.
- Check Sort keys to reorder every object's keys alphabetically, at every nesting level, before formatting or minifying.
- Click Validate at any time to check the input without changing the output box. Invalid JSON shows the exact line, column and offending snippet.
- Click Copy to copy the result to your clipboard, or Clear to start over.
How it works
Format and Minify both use the browser's built-in JSON engine:
JSON.parse turns the text into a value, and
JSON.stringify(value, null, indent) re-serializes it with your chosen indent
(Minify omits the indent argument, which drops all whitespace). Checking
Sort keys first walks the parsed value recursively, rebuilding every object
with Object.keys() sorted alphabetically; arrays are walked but left in their
original order, since array order carries meaning in JSON while object key order does
not.
Keys is the total number of property names across the whole document.
Max depth is the deepest chain of nested objects or arrays — a plain object
or array on its own is depth 1, one nested inside it is depth 2, and so on; a bare value
like 42 is depth 0. Size is the UTF-8 byte length via
TextEncoder, which can exceed the character count once the JSON contains
non-ASCII text.
For errors, browsers report the failure point differently: some give a character position,
some a line and column, and some neither. This tool reads whichever is given and converts a
position to a line/column by counting newlines; when neither is given, it falls back to
scanning for the most common invalid patterns — a comma right before }/],
single quotes, an unquoted key, a comment, or a bare NaN/undefined
— and points at the earliest one, so this step never throws. Parsing only runs on a button
click for large input, and after a short pause for small input, so typing stays smooth even
with multi-megabyte files.
Examples
Input (183 bytes):
{"name":"Ada Lovelace","role":"Mathematician","born":1815,"active":true,"skills":["Analytical Engine","Mathematics","Writing"],"address":{"city":"London","country":"UK"},"notes":null}
Output (245 bytes) — 9 keys, max depth 2:
{
"name": "Ada Lovelace",
"role": "Mathematician",
"born": 1815,
"active": true,
"skills": [
"Analytical Engine",
"Mathematics",
"Writing"
],
"address": {
"city": "London",
"country": "UK"
},
"notes": null
}
Input:
{
"name": "Ada Lovelace",
"skills": ["math", "logic",]
}
Result: Invalid JSON — line 3, column 29.
"skills": ["math", "logic",]
^
The comma right before the closing ] is not allowed in JSON. Removing it —
["math", "logic"] — makes the document valid.
Input:
{
"zebra": 1,
"apple": { "beta": 2, "alpha": 1 },
"mango": [3, 1, 2]
}
Output with Sort keys checked:
{
"apple": {
"alpha": 1,
"beta": 2
},
"mango": [
3,
1,
2
],
"zebra": 1
}
Object keys move to alphabetical order at every level (apple,
mango, zebra; then alpha, beta inside
apple). The array [3, 1, 2] keeps its original order — sorting
reorders object keys only, never array elements.
JSON syntax rules
JSON (JavaScript Object Notation, RFC 8259) is a small, strict text format. The rules that trip people up most:
- Object keys and all string values must use double quotes — never single quotes or unquoted text.
- No trailing commas after the last item in an object or array.
- No comments — neither
//nor/* */exist in JSON, even though many editors allow them in "JSON with comments" config files. - Only six value types are allowed: string, number, object, array,
true/false, andnull. There is no date, function,undefined,NaN, orInfinitytype. - Numbers cannot have a leading
+, leading zeros (007), or a trailing decimal point (1.); a leading-is allowed. - A document can be any JSON value at the top level — an object, an array, a string, a
number, or a boolean — not only
{}or[].
Common errors, before and after
| Problem | Before (invalid) | After (valid) |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'a': 1} | {"a": 1} |
| Unquoted key | {a: 1} | {"a": 1} |
NaN / undefined | {"a": NaN, "b": undefined} | {"a": null, "b": null} |
| Comments | { "a": 1 // note } | { "a": 1 } |
JSON vs. JavaScript object literal
JSON looks like a JavaScript object literal but is a stricter subset of it. A JavaScript
object literal — the syntax you write directly in .js code — allows unquoted
keys, single quotes, trailing commas, comments, functions, and values like
undefined and NaN. JSON, a pure data-interchange format, allows
none of that: it exists to be parsed by any language, not only JavaScript, so its grammar is
deliberately small and unambiguous. JSON.parse rejects anything that is valid
JavaScript but not valid JSON, which is exactly why code like {status: 'ok'}
(a normal JS object literal) fails when pasted straight into a JSON parser.
Pretty vs. minified — when to use which
Use pretty-printed (indented) JSON while developing: reading API responses, editing configuration files, debugging test fixtures, or reviewing a diff in version control, where each key sits on its own line. Use minified JSON for anything sent over a network or stored at scale — API responses, embedded config, log payloads — where every extra space and newline adds bytes with no benefit to a machine reader. A 2-space indent is the most common default for source-controlled files; 4 spaces or tabs can be easier to scan in deeply nested documents.
Frequently asked questions
Does this tool send my JSON anywhere?
No. Parsing, formatting and validating all happen in your browser. Nothing you paste is uploaded, logged, or stored — closing or reloading the tab clears it.
Why does the error point at a different line than I expected?
A JSON error is reported where the parser can no longer continue, often one token after the real mistake. A trailing comma is flagged where a new key or a closing brace was expected — right after the comma, not at the comma itself.
What is the maximum JSON size this tool can handle?
There is no hard limit — it depends on your device's memory. Multi-megabyte files parse in well under a second, and formatting only runs on a button click, never on every keystroke, so large input does not make the page feel slow while you edit it.
Does Sort keys change what my JSON means?
No, for standard consumers. Per RFC 8259, object members are an unordered set of name/value pairs, so a compliant reader must not depend on key order — array order, by contrast, always matters and is left untouched.
Why did my numbers change slightly after formatting?
JSON numbers pass through a JavaScript double-precision float. Very long integers (beyond about 15–17 significant digits) can look different even though the parsed value is unchanged. For IDs that must stay exact, store them as strings instead of bare numbers.
Related tools
- Regex Tester — test regular expressions against sample text.
- Word Counter — count words, characters and reading time.
- Color Contrast Checker — check WCAG contrast ratios for text and UI colors.
- Unit Converter — convert length, weight and temperature units.