Start with the parser error, then inspect nearby text
Most JSON errors come from small syntax issues. Start with quotes, commas, brackets, and braces before you assume the data itself is wrong. Parser errors usually point to the place where parsing became impossible, but the real mistake may be just before that spot.
A safe debugging pattern is:
- Format or validate the JSON locally when possible.
- Read the reported line, column, or unexpected token.
- Inspect the few characters before that location.
- Fix one issue at a time.
- Validate again before changing the data itself.
If the JSON contains secrets, customer data, request headers, or account identifiers, redact a small representative sample first. How to Format JSON Without Uploading Your Data is a good starting point for local review.
If you are not sure whether you need formatting, syntax validation, or schema validation, read JSON Formatter vs JSON Validator: What Is the Difference? first.
1. Single quotes instead of double quotes
JavaScript lets you write strings with single quotes. JSON does not. In strict JSON, strings must use double quotes.
Invalid:
{ 'name': 'CrateX.app', 'local': true }
Valid:
{ "name": "CrateX.app", "local": true }
This applies to both keys and string values. Numbers, booleans, arrays, objects, and null are not quoted unless you intentionally want them to be strings.
2. Trailing commas
Trailing commas are common in JavaScript, TypeScript, and some configuration formats, but they are invalid in strict JSON.
Invalid:
{
"enabled": true,
"retries": 3,
}
Valid:
{
"enabled": true,
"retries": 3
}
The same rule applies inside arrays:
["read", "write",]
Remove the final comma after the last item:
["read", "write"]
3. Comments in JSON
Strict JSON does not support comments. If your file contains // or /* */, it may be JSONC, JSON5, or another configuration format rather than JSON.
Invalid:
{
// Enable preview mode
"preview": true
}
To make it strict JSON, remove the comment or represent the explanation as data:
{
"preview": true
}
If you are editing a tool-specific config file, check the file format before removing comments. Some tools intentionally use JSONC and expect comments to remain.
4. Missing commas between properties
Adjacent object properties and array items must be separated by commas. When a comma is missing, the parser often reports an “unexpected string” or “unexpected token” error on the next line.
Invalid:
{
"id": "evt_123"
"status": "processed"
}
Valid:
{
"id": "evt_123",
"status": "processed"
}
When the parser points at the second property, inspect the previous line first.
5. Unescaped quotes inside strings
A quote inside a JSON string must be escaped with a backslash. Otherwise the parser thinks the string ended too early.
Invalid:
{ "message": "Use the "preview" mode" }
Valid:
{ "message": "Use the \"preview\" mode" }
If the string contains a lot of quotes, consider whether you are trying to embed JSON inside JSON. In that case, keep the nested JSON as a properly escaped string or store it as a real nested object instead.
6. Unescaped newlines inside strings
A JSON string cannot contain a literal line break. Use \n when the newline is part of the string value.
Invalid:
{
"message": "Line one
Line two"
}
Valid:
{
"message": "Line one\nLine two"
}
For multiline content, make sure the system that generates the JSON escapes newline characters before sending or storing the data.
7. Invalid values: undefined, NaN, and Infinity
JSON supports only these value types: object, array, string, number, boolean, and null. Values such as undefined, NaN, and Infinity are JavaScript values, not JSON values.
Invalid:
{
"limit": Infinity,
"fallback": undefined,
"score": NaN
}
Valid:
{
"limit": null,
"fallback": null,
"score": null
}
Use null, a finite number, or a domain-specific string depending on what your application expects.
8. Smart quotes copied from rich text
Text copied from documents, chat tools, or websites may contain curly quotes instead of straight quotes. They look similar, but they are different characters.
Invalid:
{ “status”: “ok” }
Valid:
{ "status": "ok" }
If a sample looks correct but still fails near a quote, check whether the quote characters are actually " rather than “ or ”.
9. Leading zeros or invalid number formats
JSON numbers have strict rules. Leading zeros are not allowed, and special number formats may fail.
Invalid:
{
"month": 06,
"ratio": .5,
"hex": 0xff
}
Valid:
{
"month": 6,
"ratio": 0.5,
"hex": "0xff"
}
If a value is an identifier rather than a number you plan to calculate with, store it as a string. That is often safer for codes, ZIP codes, invoice IDs, and external identifiers.
10. Extra text around the JSON
Logs often wrap JSON inside timestamps, labels, stack traces, or request metadata. A JSON parser expects one JSON value, not a whole log line.
Invalid as JSON:
2026-06-14T10:30:00Z INFO payload={"status":"ok","id":"evt_123"}
Extract the JSON value before validating:
{ "status": "ok", "id": "evt_123" }
If the log contains escaped JSON inside a string, you may need to unescape it before formatting the inner value.
11. Mismatched brackets or braces
Every { needs a matching }, and every [ needs a matching ]. When a closing character is missing, the parser may only fail at the end of the input.
Invalid:
{
"items": [
{ "id": "a" },
{ "id": "b" }
}
Valid:
{
"items": [{ "id": "a" }, { "id": "b" }]
}
Formatting a valid sample makes nesting easier to see. If formatting fails, reduce the JSON to a smaller sample and add sections back one at a time.
12. Confusing JSON with JSONC or JSON5
JSONC and JSON5 are useful formats, but they are not strict JSON. They may allow comments, trailing commas, unquoted keys, single quotes, or additional number formats.
Example JSON5-style input:
{
retries: 3,
// local-only setting
debug: true,
}
Strict JSON version:
{
"retries": 3,
"debug": true
}
Before fixing a file, confirm what the receiving system expects. A browser API, webhook, HTTP JSON request body, or .json file usually expects strict JSON.
Practical debugging checklist
- Validate the smallest sample that reproduces the error.
- Look just before the reported token, not only at the token itself.
- Check quotes, commas, brackets, and braces first.
- Remove comments and trailing commas when the target format is strict JSON.
- Replace JavaScript-only values with JSON values.
- Extract JSON from log wrappers before formatting.
- Keep identifiers as strings when leading zeros or exact formatting matters.
- Redact sensitive values before sharing screenshots or examples.
FAQ
Why does my JSON fail when it works in JavaScript?
JavaScript object literals are more permissive than JSON. JSON requires double-quoted strings, no comments, no trailing commas, and no values such as undefined, NaN, or Infinity.
Why does the error location seem wrong?
The parser reports where it could no longer continue. The actual mistake is often earlier, especially with missing commas, quotes, or closing brackets.
Should I auto-fix invalid JSON?
Only when you understand what the fix changes. Removing comments, converting quotes, or replacing invalid values can alter meaning. For production data, fix the source generator when possible.
Is syntax validation enough before sending an API request?
No. Syntax validation confirms that the body is parseable JSON. You may still need schema validation, required fields, allowed enum checks, authentication rules, and app-specific validation.