How to use the JSON checker
- Paste JSON into the box, drop a file on it, or click Open file.
- Read the result below the box. Valid JSON shows its type, the number of keys and values, nesting depth and size in bytes.
- For invalid JSON, press Go to error to put the cursor on the problem, fix it, and the check runs again immediately.
- Fix errors one at a time. A single missing bracket can confuse everything after it, so the first error is the one that matters.
Common JSON errors and how to fix them
Most invalid JSON comes from writing it by hand or copying a JavaScript object literal, which allows more than JSON does. The validator recognises these cases and says so in the hint:
| Mistake | Invalid example | Fix |
|---|---|---|
| Trailing comma | [1, 2, 3,] | Delete the comma after the last item. |
| Single quotes | {'name': 'Ana'} | Use double quotes for keys and strings. |
| Unquoted key | {name: "Ana"} | Quote every key: {"name": "Ana"}. |
| Comment | {"a": 1 // note} | Remove // and /* */ comments. |
| Missing comma | {"a": 1 "b": 2} | Put a comma between members. |
| Python or JS literal | {"ok": True, "x": undefined} | Use true, false and null only. |
| Raw line break in a string | "line one
line two" | Escape it as \n. |
| Leading zero | {"zip": 02134} | Write 2134, or store it as the string "02134". |
What counts as valid JSON
The validator follows RFC 8259 (the same grammar as ECMA-404). In short:
- The whole text is one value. Since RFC 7159 that value may be any type, so
"hello"and42on their own are valid JSON. - Whitespace between tokens may only be space, tab, line feed or carriage return. A non-breaking space copied from a web page is an error, and the validator points it out.
- Numbers are decimal, with an optional minus sign, fraction and exponent. Hex, octal,
NaNandInfinityare not allowed. - Object keys should be unique. Duplicates are technically allowed but behave unpredictably, so they are reported as warnings rather than errors.
Validate JSON in code
Browsers and runtimes word their parse errors differently, and some only give a character offset. That is why this JSON online validator uses its own strict parser: the message and position are the same in every browser. In your own code, the standard approach is a parse inside error handling:
// JavaScript
function isValidJson(text) {
try { JSON.parse(text); return true } catch { return false }
}
# Python
import json
try:
json.loads(text)
except json.JSONDecodeError as e:
print(e.lineno, e.colno, e.msg)Valid syntax is not the same as the right shape: to check that required fields exist and have the right types, describe them with a JSON Schema and validate against it. Once the syntax is fixed, the JSON formatter can pretty print the result.