10 Most Common JSON Mistakes Developers Make (and How to Fix Each One)
Trailing commas, unquoted keys, Python True/False, missing quotes — the 10 JSON errors that break your code, with exact before/after fixes and a free one-click repair tool.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →JSON looks simple. Six value types, one string format, two container types. And yet it produces more parse errors than almost any other data format developers work with daily. The specification is strict, but most tools that generate JSON — AI models, templating engines, manual editing — operate at a higher level of abstraction and routinely produce output that violates one of JSON's few hard rules.
Here are the 10 most common JSON mistakes, with exact before/after examples for each.
1. Trailing Commas After the Last Element
What it looks like:{
"name": "Alice",
"role": "admin",
"active": true,
}
[
"apple",
"banana",
"cherry",
]
Why it happens: JavaScript, Python, and most modern languages allow trailing commas in their own syntax (ES5+ arrays and objects, Python lists and dicts). Developers who write JSON by hand, or AI models trained on JavaScript/Python code, carry this habit into JSON where it's forbidden.
Why it breaks: The JSON specification (RFC 8259, Section 4 and 5) explicitly excludes a trailing comma from the grammar. There is no optional comma after the last value.
The fix: Remove the comma after the last element before } or ].
{
"name": "Alice",
"role": "admin",
"active": true
}
2. Single Quotes Instead of Double Quotes
What it looks like:{
'name': 'Alice',
'role': 'admin'
}
Why it happens: Python uses single quotes as its idiomatic string delimiter. Developers copying from Python print() output, or AI models prompted with Python examples, produce single-quoted JSON.
Why it breaks: JSON (RFC 8259, Section 7) mandates double quotes for strings. Single-quoted strings are a JavaScript and Python construct. JSON has no concept of "either quote character."
The fix: Replace all single-quoted strings and keys with double-quoted ones. Be careful: if any value contains a literal single quote, it must remain unescaped inside the converted double-quoted string (don't stays as don't).
{
"name": "Alice",
"role": "admin"
}
3. Unquoted Keys
What it looks like:{
name: "Alice",
role: "admin",
active: true
}
Why it happens: JavaScript object literal syntax does not require keys to be quoted when they are valid identifiers. Developers writing "JSON" from memory, or AI models writing JavaScript object notation, produce unquoted keys.
Why it breaks: JSON requires all object keys to be strings enclosed in double quotes. Period. There is no exception for simple alphanumeric keys.
The fix: Quote every key.
{
"name": "Alice",
"role": "admin",
"active": true
}
4. Comments Inside JSON
What it looks like:{
// Database configuration
"host": "localhost",
"port": 5432, / default PostgreSQL port /
"database": "myapp"
# legacy field removed
}
Why it happens: Configuration files almost always support comments. YAML, TOML, INI, .env, and even JavaScript all allow comments. JSON5 and JSONC (JSON with Comments) allow them too — but these are supersets of JSON, not JSON itself.
Why it breaks: The JSON specification has no comment syntax. //, / /, and # are all invalid JSON tokens.
The fix: Remove all comments. If you need comments in configuration files, use YAML, TOML, or JSONC instead.
{
"host": "localhost",
"port": 5432,
"database": "myapp"
}
5. Using undefined, NaN, or Infinity as Values
What it looks like:{
"score": NaN,
"ratio": Infinity,
"missing": undefined
}
Why it happens: NaN, Infinity, and undefined are JavaScript primitives. JSON.stringify() in JavaScript silently converts undefined to nothing and NaN/Infinity to null. But code that builds JSON by string concatenation or template literals — or AI models that output these values — produces invalid JSON.
Why it breaks: JSON has six value types: string, number, object, array, boolean (true/false), and null. NaN, Infinity, and undefined are not any of these. They have no representation in the JSON specification.
The fix: Replace with null, or with a numeric representation if semantically appropriate (e.g., -1 for "not available").
{
"score": null,
"ratio": null,
"missing": null
}
6. Python True/False/None Instead of true/false/null
What it looks like:{
"active": True,
"deleted": False,
"metadata": None
}
Why it happens: This is the most common mistake from AI models, particularly when prompted with Python context or when the model was fine-tuned on Python data. True, False, and None are Python's boolean and null literals — they are capitalised differently from JSON's true, false, and null.
Why it breaks: JSON is case-sensitive. True is not true. The JSON parser sees an unquoted identifier starting with T and throws an immediate syntax error.
The fix: Replace capitalised Python literals with their lowercase JSON equivalents.
{
"active": true,
"deleted": false,
"metadata": null
}
This is the mistake most often found in AI-generated JSON and one of the first things AI JSONMedic checks for.
7. Missing Commas Between Elements
What it looks like:{
"name": "Alice"
"role": "admin"
"active": true
}
[
"apple"
"banana"
"cherry"
]
Why it happens: Manual editing — deleting a line and forgetting the comma on the line above. Also common when developers or AI models add a new field without checking whether the preceding field already has a trailing comma.
Why it breaks: JSON requires a comma between every adjacent key-value pair in an object and between every element in an array.
The fix: Add commas between every element. The easiest approach: use a formatter that auto-repairs missing commas — the JSON Formatter can do this while pretty-printing, and AI JSONMedic handles missing comma insertion as one of its repair stages.
{
"name": "Alice",
"role": "admin",
"active": true
}
8. Truncated or Incomplete JSON from Streaming AI
What it looks like:{
"summary": "This is a long generated text that was cut off before the AI
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"},
{"id": 3, "name": "Ca
Why it happens: Language model APIs have output token limits. When a JSON object is too long to fit within the model's max_tokens parameter, the output is cut off mid-generation. The result is structurally incomplete JSON — unclosed strings, unclosed arrays, unclosed objects.
Why it breaks: JSON requires every opened string, array, and object to be closed. Truncated output fails at the parser's most fundamental check.
The fix:
- Prevent it: Set
max_tokenshigh enough, or use structured output / function calling with your AI provider to guarantee valid JSON. - Repair it: A smart JSON repair tool can close unclosed strings and brackets using the nesting depth at the point of truncation. AI JSONMedic handles this as part of its truncation-repair stage.
Repaired:
{
"summary": "This is a long generated text that was cut off before the AI"
}
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"},
{"id": 3, "name": "Ca"}
]
9. Duplicate Keys
What it looks like:{
"name": "Alice",
"role": "admin",
"name": "Bob"
}
Why it happens: Manual editing — adding a field that already existed. Also common when merging two JSON objects by hand or when an AI generates a response and includes a field twice.
Why it's subtle: Duplicate keys are not technically forbidden by the JSON specification (RFC 8259, Section 4 says it "SHOULD" not happen, not "MUST NOT"). Most parsers accept them silently — but they resolve duplicates differently:
JSON.parse()in JavaScript: last value wins ("name"→"Bob")- Python's
json.loads(): last value wins - Some parsers: first value wins
- A few parsers: throw an error
{
"name": "Bob",
"role": "admin"
}
10. Non-String Keys (Numbers as Keys)
What it looks like:{
1: "first",
2: "second",
3: "third"
}
Why it happens: In Python, dictionary keys can be any hashable type — including integers. When Python code serialises a dict with integer keys using str(key) manually or through json.dumps(), the output may use numeric keys. AI models trained on Python code produce this pattern.
Note: Python's built-in json.dumps() actually raises a TypeError for non-string keys by default (unless skipkeys=True is used). This pattern more commonly comes from manual string concatenation, template rendering, or AI output.
Why it breaks: JSON object keys must be strings. Always. No exceptions. Numeric keys are a JavaScript and Python concept, not a JSON concept.
The fix: Wrap every key in double quotes.
{
"1": "first",
"2": "second",
"3": "third"
}
If these are sequential identifiers, consider whether an array is a better fit for the data:
["first", "second", "third"]
Fix All of These Automatically
Working through 10 categories of JSON errors by hand is tedious. Every mistake described in this guide — trailing commas, single quotes, Python literals, comments, missing commas, truncation, duplicate key detection — is handled automatically by AI JSONMedic, the free JSON repair tool built specifically for these patterns.
Paste your broken JSON, click Fix, and get back valid JSON with a repair report showing every change made and why. No sign-up required, and JSON never leaves your browser.
The JSON Validator is also useful when you want to know what is wrong without automatically fixing it — it gives a precise line number, character position, and plain-English description of the first error, which is helpful when debugging code that generates JSON and you need to trace the problem to its source.
For inspecting large or minified JSON, the JSON Formatter pretty-prints it with proper indentation so the structure is immediately readable. And the JSON Diff Tool lets you compare two versions of a JSON document side-by-side — useful when you've repaired a response and want to confirm the changes are exactly what you intended.
The JSON specification is only 10 pages. The mistakes are predictable. The fixes are mechanical. The right tooling makes them instantaneous.
For a focused breakdown of the most common error message developers encounter, see the JSON Parse Error guide. And if you're comparing tools for handling these errors at scale, the Best JSON Repair Tools 2026 comparison covers the leading options side by side.
FAQ
What is the most common JSON mistake developers make?
Trailing commas — writing {"a": 1, "b": 2,} with a comma after the last item. This is valid JavaScript but invalid JSON. The second most common is using single quotes instead of double quotes. Both mistakes come from muscle memory of JavaScript object syntax.
Why does JSON not allow trailing commas?
JSON was designed in 2001 as a strict, minimal data interchange format derived from a subset of JavaScript. The designers chose simplicity and cross-language compatibility over convenience. Every valid JSON document parses identically in every language — trailing commas would add parsing ambiguity that doesn't exist today.
Can I use comments in JSON?
No — standard JSON does not allow comments. If you need comments in configuration files, use JSONC (JSON with Comments, used by VS Code and TypeScript's tsconfig.json) or JSON5. Both are supersets of JSON that allow // and / / comments. Strip comments before passing to JSON.parse().
What is the difference between null, undefined, and missing in JSON?
In JSON, null is an explicit value (serializes as null). undefined is not a valid JSON value — properties with undefined values are silently dropped during JSON.stringify(). A "missing" property and a property set to undefined are indistinguishable after serialization. Use null for explicitly absent values that need to be communicated.
How do I validate JSON before using it in production?
Parse it with JSON.parse() in a try/catch for syntax validation, then apply schema validation with Zod (TypeScript), Pydantic (Python), or Ajv (JSON Schema) to verify the shape. Both layers are necessary: syntax validation catches malformed JSON, schema validation catches data contract violations like missing required fields or wrong types.
Still dealing with broken JSON?
Paste it in and get it fixed in under 1 second — free, no signup, no install. Works with ChatGPT, Claude, n8n, and any AI output.
Fix My JSON Free →Related Articles