How can I catch new posts?
Bookmark this blog and watch the homepage and tools hub—we surface new guides there. No account or mailing list is required to read articles.
A practical guide to JSON errors involving quotes, commas, brackets, escapes, unsupported values, duplicate keys, and large integers—with broken examples and reliable fixes.
JSON looks simple, but one misplaced quote, comma, or backslash can make an entire document fail to parse. A parser usually reports where it could no longer continue—not necessarily where the mistake began.
This guide covers the JSON problems developers encounter in API responses, configuration files, and logs. Each section explains the cause, shows broken and corrected input, and suggests a safe fix. Start with the JSON Validator to locate the first error. If the input is only JSON-like, use the JSON Repair Tool to produce a candidate, then review every change. Processing stays in your browser.
Quick rule: preserve the original input, fix the first error, and validate again after every change.
JSON supports objects, arrays, strings, numbers, booleans, and null. Object keys and strings require double quotes. Comments, undefined, NaN, functions, and date objects are not part of JSON.
Text copied from JavaScript, Python, logs, or a configuration language may look like JSON without being valid JSON. Identifying the source first prevents unsafe search-and-replace fixes.
| Message or symptom | Likely cause | Check first |
|---|---|---|
Unexpected token | Illegal character, single quote, or unquoted key | Quotes around the reported position |
Unexpected end of JSON input | Missing delimiter or truncated input | The end of the file or response |
Expected ',' or '}' | Missing comma between properties | The end of the previous value |
Bad control character | Raw newline or tab inside a string | Backslashes and control characters |
| Parsing succeeds but values change | Duplicate keys or unsafe integers | Data semantics and types |
Standard JSON requires double quotes around both property names and strings. JavaScript objects allow single quotes and unquoted keys, which is why copying an object literal often causes this error.
Broken:
{
name: 'Alice',
'role': 'admin'
}Valid JSON:
{
"name": "Alice",
"role": "admin"
}Do not replace every single quote in the document blindly. Apostrophes and escaped characters inside strings can make a global replacement corrupt valid data.
The parser may highlight the next property even though the actual mistake is at the end of the previous line.
Broken:
{
"name": "Alice"
"active": true
}Fixed:
{
"name": "Alice",
"active": true
}The same rule applies to array elements. When you see Expected ',', inspect the complete value immediately before the reported position.
JavaScript and some configuration formats allow trailing commas. Standard JSON does not.
Broken:
{
"name": "Alice",
"active": true,
}Fixed:
{
"name": "Alice",
"active": true
}Remove the comma after the final object property or array item. Then run the result through the JSON Beautifier to parse it again and normalize the indentation.
Unexpected end of JSON input means the parser reached the end while an object, array, or string was still open. It can also mean that a network response, copied log, or file was truncated.
Broken:
{
"user": {
"name": "Alice",
"tags": ["admin", "editor"]
}Fixed:
{
"user": {
"name": "Alice",
"tags": ["admin", "editor"]
}
}Do not automatically append a brace to API data until you confirm the response is complete. A tool can close the syntax, but it cannot recover missing records or fields.
JSON uses backslashes for escapes. Quotes, backslashes, newlines, and tabs inside strings must be written as \", \\, \n, and \t. Windows paths and regular expressions are common trouble spots.
Broken:
{
"path": "C:\new\reports",
"message": "He said "hello""
}Fixed:
{
"path": "C:\\new\\reports",
"message": "He said \"hello\""
}A JSON string also cannot contain a raw line break. Use \n when the value needs a newline.
Standard JSON does not support // or /* ... */ comments.
{
// Production API endpoint
"apiUrl": "https://api.example.com"
}Remove the comment, or preserve necessary documentation as an explicit field. Avoid a simple regular expression that deletes everything after //: it can also destroy URLs such as https://api.example.com. A safe repair process must recognize string boundaries first.
JSON booleans and null must be lowercase: true, false, and null. Python-style True, False, and None, SQL-style NULL, and JavaScript values such as undefined, NaN, and Infinity are invalid.
Broken:
{
"active": True,
"nickname": None,
"score": NaN
}Possible repair:
{
"active": true,
"nickname": null,
"score": null
}This is not always a mechanical conversion. Whether NaN should become null, a string, or a missing field is a business decision.
Log systems often write one JSON object per line. This is usually NDJSON or JSON Lines; the individual lines can be valid while the full text is not one JSON document.
{"id": 1, "status": "ok"}
{"id": 2, "status": "failed"}If the consumer expects standard JSON, convert the records into an array:
[
{"id": 1, "status": "ok"},
{"id": 2, "status": "failed"}
]Adding only square brackets is not enough: objects need commas between them, and every line must be complete.
If parsing succeeds but returns one long string full of backslashes, the data was probably serialized twice.
"{\"name\":\"Alice\",\"active\":true}"The first parse produces a string; the second produces the object. The preferred fix is usually to serialize once at the source. Before changing it, check the API contract—some fields intentionally store JSON as text.
This input may be accepted even though role appears twice:
{
"role": "user",
"role": "admin"
}Many parsers keep the last value, but languages and security layers can disagree. Reject duplicate keys during ingestion and fix the producer. After a normal JSON.parse, the overwritten value is already lost, so inspecting only the parsed object may be too late.
JSON syntax allows large numbers, but JavaScript Number cannot represent every integer above 9007199254740991 exactly. Database IDs and snowflake IDs can change during parsing.
Risky:
{
"userId": 9007199254740993
}Safer for identifiers:
{
"userId": "9007199254740993"
}If the value must support arithmetic, producers and consumers need an agreed arbitrary-precision strategy. Converting an already rounded number to a string cannot restore the original digits.
Do not automatically rewrite payment, permission, medical, audit, or migration data without review. Tools can resolve unambiguous syntax problems; they cannot infer missing values or business meaning.
Most JSON parsing failures come from quotes, commas, delimiters, escapes, and non-standard values. Preserve the source, fix the first error, and validate after every change. Once parsing succeeds, continue checking duplicate keys, integer precision, types, and semantics. For JSON-like input, start with the JSON Repair Tool, then independently verify it with the JSON Validator and JSON Diff.
Dedicated to providing developers with the best JSON processing tools
More posts coming soon...
Back to BlogFollowing the blog, topics we cover, and how to suggest guides.
Bookmark this blog and watch the homepage and tools hub—we surface new guides there. No account or mailing list is required to read articles.
JSON validation, formatting, conversion, debugging workflows, and JSON Work releases—mapped to what the free on-site tools can do locally in your browser.
Yes. Reach out via the About page or GitHub; we prioritize guides tied to real integration and debugging scenarios.