Common JSON parse errors (and how to fix them)
JSON is strict. Many “JSON parse errors” happen because the input is actually JavaScript object literal syntax (or a config format) rather than valid JSON.
1) Trailing commas
JSON does not allow a comma after the last item in an object/array.
// ❌ invalid JSON
{
"a": 1,
}
// ✅ valid JSON
{
"a": 1
} 2) Single quotes
JSON strings and object keys must use double quotes.
// ❌ invalid JSON
{ 'a': 'b' }
// ✅ valid JSON
{ "a": "b" } 3) Comments
JSON doesn’t support // or /* */
comments.
// ❌ invalid JSON
{
"a": 1 // comment
} 4) Unquoted keys
In JSON, object property names must be quoted.
// ❌ invalid JSON
{ a: 1 }
// ✅ valid JSON
{ "a": 1 } 5) NaN / Infinity
JSON only supports finite numbers. Use null or a string if
you need placeholders.
// ❌ invalid JSON
{ "value": NaN }
// ✅ valid JSON
{ "value": null } 6) Using the wrong top-level type
Some APIs expect an object, but you provided an array (or vice versa). That’s valid JSON, but it still may break your app.
Try it instantly
Paste your JSON into the formatter to see exact error locations: JSON Formatter.
Related
- JWT Decoder (JWT payloads are JSON)
- Base64 Encoder & Decoder (some payloads are Base64-encoded)
- All tools