Repair common JSON syntax errors and validate your data.
Invalid JSON usually comes from a small syntax problem: a trailing comma, a missing comma, a single quote, an unquoted key, a comment, or a mismatched bracket. Because JSON has strict rules, even one wrong character prevents the entire document from being parsed. This guide covers every common invalid JSON pattern, shows you exactly what the correct version looks like, and explains how to fix each error — either manually or using the JSON Formatter auto-fix feature.
JSON was designed as a lightweight data interchange format that any programming language could parse reliably. To achieve that universal reliability, the specification leaves no room for ambiguity. There are no optional semicolons, no shorthand for undefined values, no tolerance for trailing commas, and no support for comments. Every key must be a double-quoted string. Every value must be one of six types: string, number, boolean, null, object, or array. A single deviation causes parsers in JavaScript, Python, Java, Go, and every other language to throw an error and refuse to continue.
This strictness is intentional — it makes JSON a predictable, language-neutral format. But it also means that JSON written by hand, copied from documentation, generated by AI tools, or modified in a text editor without JSON awareness is prone to small mistakes that are hard to spot with the naked eye.
This is the single most common JSON error. Many developers come from JavaScript, where trailing commas in objects and arrays have been valid since ES5. JSON does not allow them.
Invalid:
{
"name": "Ava",
"role": "admin",
"active": true,
}
Valid:
{
"name": "Ava",
"role": "admin",
"active": true
}
The same rule applies to arrays. ["one", "two", "three",] is invalid. Remove the comma after the last element.
JavaScript allows both single and double quotes for strings. JSON only allows double quotes — for both keys and string values.
Invalid:
{'name': 'Ava', 'role': 'admin'}
Valid:
{"name": "Ava", "role": "admin"}
Auto-fix handles this automatically. If you have a large payload with hundreds of single-quoted strings, paste it into the formatter and click Auto-fix rather than replacing them manually.
In JavaScript object literals, keys do not need to be quoted. In JSON, every key must be a quoted string — no exceptions.
Invalid:
{name: "Ava", active: true, score: 42}
Valid:
{"name": "Ava", "active": true, "score": 42}
This error is common when copying JavaScript object literals from source code into a JSON file or API payload field.
JSON has no comment syntax. Neither // single-line comments nor /* */ block comments are valid anywhere in a JSON document.
Invalid:
{
// The user's display name
"name": "Ava",
"score": 42
}
Valid:
{
"name": "Ava",
"score": 42
}
If you need to annotate JSON for human readers, move comments to a separate documentation file or use a format like JSONC (JSON with Comments), which is supported by some editors but is not standard JSON.
Each key-value pair in a JSON object, except the last, must be followed by a comma. A missing comma causes an "Unexpected token" error on the next property.
Invalid:
{
"name": "Ava"
"role": "admin"
}
Valid:
{
"name": "Ava",
"role": "admin"
}
JSON has no representation for undefined, NaN, or Infinity. These JavaScript-only values must be replaced before serialization.
Invalid:
{"result": NaN, "timeout": Infinity, "value": undefined}
Valid:
{"result": null, "timeout": 0, "value": null}
In JavaScript, JSON.stringify() silently drops undefined properties and converts NaN and Infinity to null. If your serializer is not JSON.stringify(), verify how it handles these edge cases.
Certain characters inside JSON strings must be escaped with a backslash. The most common that cause parse failures are double quotes and backslashes.
Invalid:
{"message": "He said "hello" to her", "path": "C:\Users\Ava"}
Valid:
{"message": "He said \"hello\" to her", "path": "C:\\Users\\Ava"}
Other characters requiring escaping: \n (newline), \t (tab), \r (carriage return). Newlines inside a string value must be written as \n, not as an actual line break.
A JSON object must start with { and end with }. A JSON array must start with [ and end with ]. Missing one closing character — or nesting them incorrectly — causes the parser to fail, often at the very end of the document.
Invalid:
{
"users": [
{"name": "Ava"},
{"name": "Ben"}
]
Valid:
{
"users": [
{"name": "Ava"},
{"name": "Ben"}
]
}
Deeply nested JSON is especially prone to this. The tree view in the JSON Formatter shows the nesting structure visually, making it easy to spot where a closing bracket is missing.
JSON does not allow integers to have leading zeros, because some parsers interpret them as octal notation.
Invalid:
{"zip": 01234, "code": 007}
Valid:
{"zip": "01234", "code": "007"}
If the numeric identity matters — ZIP codes, padded reference codes — represent them as strings to preserve leading zeros.
The JSON specification says object names should be unique. Some parsers accept duplicates and use the last value; others use the first; others throw an error. Remove duplicates to ensure consistent behaviour across all parsers.
Ambiguous:
{"status": "ok", "status": "error"}
Safe:
{"status": "error"}
Auto-fix handles the most common mechanical errors, but there are situations where no tool can safely repair JSON without human input. If the JSON was truncated — for example, copied from a log that cut off mid-payload — the tool can validate what it has but cannot guess missing values or closing structures. If the document has deeply inconsistent nesting, such as an array closed with a brace instead of a bracket, fix that manually using the line number the validator provides.
In these cases, work from the first reported error. Fix one problem at a time and revalidate after each change. Parsers typically report only the first error found, so fixing the first one often reveals additional errors that were hidden earlier.
The most common hidden issue is a non-visible character: a Unicode zero-width space, a byte-order mark (BOM) at the start of the file, or a curly typographic quote (“ instead of ") copied from a word processor or documentation site. Paste the text into the formatter — if it shows a character error at position 0 or 1, a BOM or invisible character is the likely cause.
Not in standard JSON. If you need annotated JSON for configuration files, consider JSONC (used by VS Code settings) or JSON5, both of which support comments. For API payloads and data exchange, comments are not appropriate — use API documentation or a JSON Schema alongside the data instead.
JavaScript object literal syntax is more permissive than JSON. JSON was derived from a strict subset of JavaScript, not the full language. As JavaScript evolved, its object syntax gained features — trailing commas, computed keys, shorthand properties — that were never added to the JSON specification. This divergence is the source of most JSON errors made by JavaScript developers.
The JSON specification does not define a maximum depth, but individual parsers impose their own limits. Most production parsers handle hundreds of nesting levels safely. If you are generating deeply nested JSON programmatically, it is worth reconsidering the data structure — most real-world JSON is fewer than ten levels deep, and flatter structures are easier to work with across all languages.
The terms are used interchangeably in practice. Strictly speaking, both refer to text that does not conform to the JSON specification and cannot be parsed by a standard JSON parser. Some developers use "malformed" specifically for structurally broken documents (unclosed brackets, truncated data) and "invalid" for syntactically wrong but complete documents (trailing commas, unquoted keys), but there is no universal distinction.
Try what you just learned — paste your JSON into the formatter and validate it instantly. Free, browser-only, no data sent anywhere.
Need to repair a payload? Paste invalid JSON and use Format or Auto-fix.
Fix JSON Now