Data formats and APIs
Common JSON errors and how to fix them
Diagnose missing commas, invalid quotes, trailing commas, broken escapes and unexpected tokens without guessing or rewriting the whole payload.
In brief
Most JSON failures become straightforward when you inspect the first parser error, the preceding token and the smallest enclosing object or array.
Why the highlighted character is not always the cause
A JSON parser reads from the beginning until the next character is impossible under the grammar. The location in an error message therefore marks where parsing failed, not necessarily where the mistake was typed. A missing comma after one property is often reported when the parser reaches the quotation mark beginning the next property.
Start at the reported position, then inspect the token immediately before it. Confirm the surrounding object or array is still open and that the parser is expecting the kind of value you supplied. Fix one issue at a time and re-run validation so later errors are not confused with the first.
Five failures that account for most malformed payloads
JSON is deliberately small and strict. It does not allow comments, undefined values, single-quoted strings or JavaScript object shorthand. Configuration copied from JavaScript, YAML or a command-line example often fails because it contains conveniences that are not part of JSON.
- Missing comma: add a comma between adjacent object members or array items.
- Trailing comma: remove the comma after the final member or item.
- Single quotes: replace them with double quotes and escape embedded double quotes.
- Invalid escape: use a defined escape such as \n, \t, \\ or a valid Unicode escape.
- Unquoted property name: wrap every property name in double quotes.
Missing comma before enabled
{
"name": "example"
"enabled": true
}Be careful with numbers and duplicate names
JSON permits a defined number grammar but does not define how every receiving implementation stores large or precise values. A long integer may be rounded when parsed into an IEEE 754 number. If an identifier must remain exact, confirm whether the API contract expects a string rather than a numeric value.
The JSON specification says object member names should be unique for interoperable behaviour, but parsers differ when duplicates appear. Some keep the last value, some report an error and some expose every pair. A formatter can therefore change what a reviewer notices without resolving the ambiguity. Remove duplicates at the source rather than relying on a parser's chosen behaviour.
A syntax validator is not a JSON Schema validator. Required fields, formats and allowed values need a separate contract check.
Use reduction instead of trial-and-error editing
For a large document, duplicate it into a safe working copy and remove half of the top-level structure. Validate again. Continue narrowing to the smallest object or array that reproduces the failure. This binary-reduction approach is faster and less error-prone than scanning thousands of lines manually.
After the syntax error is fixed, compare the corrected sample with the intended contract. Record the exact change, because a payload that parses after a field was deleted may now be syntactically valid but operationally incomplete.
Primary references
These sources support the standards and security claims in this guide. Links open on the publisher’s site.
Continue learning
How to validate JSON without uploading sensitive data
A safe, repeatable method for validating JSON locally, interpreting parser errors and recording useful evidence without exposing production payloads.
Read guideJSON versus YAML: how to convert without changing meaning
Understand quoting, scalar types, duplicate keys, anchors and multi-document input before converting configuration between JSON and YAML.
Read guide