JSON troubleshooting

How to Fix Invalid JSON Errors

Invalid JSON usually comes from a small syntax mistake: a missing comma, an extra trailing comma, an unescaped quote, or a key without double quotes. Start with the reported line and column, repair one error at a time, and validate again after every change.

At a glance

Quick answer

  • Use the reported line and column as a starting point, but inspect the token immediately before it too.
  • JSON requires double-quoted keys and strings, and it does not allow trailing commas or comments.
  • Hidden BOM characters, invalid Unicode escapes, unsafe integers, and excessive nesting can fail even when the text looks plausible.
  • Format only after the document parses successfully; formatting cannot repair ambiguous data automatically.

Start with the first reported error

A JSON parser normally stops at the first place where the document can no longer be interpreted. The line and column identify where parsing failed, not always where the original mistake began. A missing comma on the previous line, for example, may make the next property look invalid.

Read the surrounding object or array from left to right. Check the opening bracket, the previous value, the separator after that value, and the token highlighted by the parser. Fix one issue, validate again, and let the next error surface instead of editing several uncertain locations at once.

Fix the most common JSON syntax mistakes

JSON is intentionally stricter than JavaScript object syntax. Configuration copied from source code may therefore look familiar while still being invalid JSON.

  • Put double quotes around every object key and every string value.
  • Insert commas between sibling properties and array items.
  • Remove the final trailing comma before a closing brace or bracket.
  • Use true, false, and null in lowercase; undefined and NaN are not JSON values.
  • Remove comments, because standard JSON has no line-comment or block-comment syntax.

Invalid

{
  user: 'Ada',
  active: True,
}

Valid

{
  "user": "Ada",
  "active": true
}

Check quotes, backslashes, and hidden characters

A quote inside a JSON string must be escaped as \", and a literal backslash must be written as \\. Newlines inside a string must use an escape such as \n rather than a physical line break. Invalid escape sequences, such as \x, also make the document fail.

Text copied from spreadsheets, logs, or older files can begin with a byte order mark. A robust JSON tool can remove a leading BOM, but an unexpected invisible character in the middle of the document remains invalid. When the highlighted character looks normal, delete and retype the surrounding punctuation.

Escaped string

{
  "message": "She said \"hello\"",
  "path": "C:\\temp\\file.json"
}

Watch number precision and nesting depth

A document can be syntactically valid but still be unsafe to process in JavaScript. Integers larger than 9,007,199,254,740,991 cannot be represented exactly as ordinary JavaScript numbers, so identifiers of that size should usually be quoted as strings.

Extremely deep objects and arrays can exhaust the call stack or freeze a tree viewer. VetaTool limits JSON nesting to 256 levels so malformed or hostile input fails with a readable message instead of destabilizing the page.

  • Quote large IDs when exact digits matter.
  • Reject non-finite numeric results such as values that overflow to Infinity.
  • Reduce unnecessary wrapper objects if a generated document exceeds the nesting limit.

Use a repeatable repair workflow

Paste the smallest failing sample into a validator, repair the first error, and re-run validation. Once the sample is valid, apply the same correction to the original source and format the result to reveal its structure.

  • Validate before formatting or minifying.
  • Compare the repaired document with the original when the payload is important.
  • Keep API-generated identifiers and decimal values in the representation expected by the receiving system.
  • Download or copy only after the validator reports a valid document.