JSON Formatter & Validator
Format, validate and minify JSON with exact line-and-column errors and recursive key sorting, or repair JavaScript-style input.
Paste or type JSON, then choose an action.
Repair
Line numbers are those of your text before the repair.
Runs entirely in your browser. Your JSON is never uploaded.
Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Nothing is saved on this device; your JSON is kept only while the tab is open.
Added · Updated : added an optional Repair button that fixes the common errors and lists each change by line
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.
- If the input is a JavaScript object literal or a config file with comments, click Repair. It fixes the five errors listed under "Common errors" below, lists every change with its line number and formats the result; Undo repair puts your original text back. Repair runs only when you click it.
- Click Copy to copy the result to your clipboard, or Clear to start over.
This page reads only JSON. To turn YAML or CSV data into JSON first, use the YAML to JSON Converter or the CSV to JSON Converter.
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. Input of up to 50,000 characters
is checked automatically 0.35 seconds after you stop typing; longer input is checked only
when you click Format, Minify or Validate.
Repair reads the input token by token, so nothing inside a double-quoted string is changed.
It removes // and /* */ comments, turns a single-quoted string into
a double-quoted one (escaping any " inside it), adds double quotes around a bare
word that is followed by a colon, replaces NaN, Infinity,
-Infinity and undefined with null, and drops a comma
when the next token is } or ]. Other mistakes, such as a missing
comma or an unknown word, are left for you: after a repair the page validates the result and
shows any error that remains.
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,
so the array reads ["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.
Input:
{
name: 'Ada', // first name
tags: ['math', 'logic',],
score: NaN,
}
Repair: 10 changes
Line 2: quoted the key: name → "name"
Line 2: single to double quotes: 'Ada' → "Ada"
Line 2: removed the comment: // first name
Line 3: quoted the key: tags → "tags"
Line 3: single to double quotes: 'math' → "math"
Line 3: single to double quotes: 'logic' → "logic"
Line 3: removed the trailing comma before ]
Line 4: quoted the key: score → "score"
Line 4: NaN → null
Line 4: removed the trailing comma before }
Output (2-space indent):
{
"name": "Ada",
"tags": [
"math",
"logic"
],
"score": null
}
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/* */exists 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, a boolean or
null), not only{}or[].
A JavaScript object literal allows unquoted keys, single quotes, trailing commas, comments
and values such as undefined, which is why code such as
{status: 'ok'} fails when pasted here: JSON keeps its grammar small so that any
language can parse it. Keep JSON indented while you read or edit it, and minify it when it is
sent or stored in bulk, where spaces and newlines only add bytes.
Common errors, before and after
The Repair button applies every row of this table.
| 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 } |
Frequently asked questions
Why does the error point at a different line than I expected?
Browsers word the error differently. If the message gives a position, the caret marks where the parser could no longer continue, often one token after the real mistake: for a trailing comma, the closing bracket or brace, which may sit on the next line. If it gives none, as Chromium-based browsers do for a trailing comma inside an array, the page's own scan marks the comma itself, as in Example 2.
What is the maximum JSON size this tool can handle?
There is no fixed limit; it depends on your device's memory. Formatting and minifying run only when you click a button, and input over 50,000 characters is not checked while you type.
Does Sort keys change what my JSON means?
No, for standard consumers. RFC 8259 defines an object as an unordered collection of name/value pairs, and software that does not depend on member order reads the sorted and the original document the same way. Array order 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.
Sources
- Bray T, ed. (2017). The JavaScript Object Notation (JSON) Data Interchange Format. RFC 8259, Internet Engineering Task Force. The standard behind the syntax rules above: the value types, no leading zeros in numbers, any value at the top level, and objects as unordered collections of name/value pairs.