JSON is strict by design
JSON has a small grammar, which makes it portable between programming languages. The same strictness also makes tiny punctuation mistakes fail parsing. Start with the first error reported by a validator; later errors may be side effects of that one problem.
Property names or strings use single quotes
JSON requires double quotes around property names and string values.
// Invalid
{'name': 'LXB Hub'}
// Valid
{"name": "LXB Hub"}Single-quoted strings may be valid JavaScript, but a JavaScript object literal is not automatically valid JSON.
A trailing comma appears after the last item
The last property in an object and the last value in an array cannot be followed by a comma.
// Invalid
{"games": 5, "tools": 5,}
// Valid
{"games": 5, "tools": 5}A comma, colon, quote, or bracket is missing
Properties need a colon between the name and value, while neighboring properties need a comma. Strings must close with a matching double quote. Objects use braces and arrays use brackets. When nesting is deep, format the surrounding valid section and compare each opening character with its closing partner.
The input contains unsupported values
JSON supports strings, numbers, booleans, null, arrays, and objects. Values such as undefined, NaN, comments, functions, dates, and regular expressions are not part of JSON. Represent a date as a string, and decide explicitly whether a missing value should be omitted or stored as null.
A string contains an unescaped character
A double quote inside a string must be escaped as \". Backslashes in paths also need escaping. Actual line breaks cannot appear unescaped inside a JSON string; use \n when the newline is part of the value.
Numbers use a non-JSON form
JSON numbers cannot include leading plus signs, hexadecimal notation, or leading zeros such as 007. Store identifiers such as postal codes and account references as strings when their leading zeros are meaningful.
Validate with a small repeatable loop
- Use the JSON validator to locate the first parser failure.
- Inspect a small area before and after that position.
- Fix one structural problem.
- Validate again before changing anything else.
Once validation succeeds, format the JSON and review the visible hierarchy. Valid syntax does not guarantee that the values or structure match what an application expects.