Missing bracket in JSON: How to Fix It in Python
Python has no error called 'Missing bracket'. json.loads() reports it as Expecting ',' delimiter or a similar message. Learn how to find the unclosed…
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →A missing bracket means an opening [ or { has no matching ] or }, so the parser cannot finish the document. Python's json module reports this as JSONDecodeError, most often 'Expecting , delimiter', with a line and column near where it gave up.
What “Missing bracket in JSON” means
Python's json module does not print the words 'missing bracket'. It raises json.JSONDecodeError with a message such as Expecting ',' delimiter, and the line, column and char offset show where parsing stopped. The JSON standard requires every array and object to be closed by its own matching bracket, so an unclosed one makes the text invalid. The parser finds out only when it reads a character that cannot follow, or when the text ends early.
Causes and the fix for each
An array is closed with the wrong bracket.
The array opened with [ but was closed with }. The parser expects , or ] and finds }.
Before (fails):{"ids": [1, 2}
After (valid):
{"ids": [1, 2]}
The final closing brace is missing.
A nested object ends, but the outer object never does. The parser reaches the end of the text while still inside it.
Before (fails):{"a": {"b": 1}
After (valid):
{"a": {"b": 1}}
The text was cut off.
A network read, a log line limit or an LLM token limit can stop the output mid-document, so the closing brackets never arrive.
Before (fails):{"items": [{"id": 1}, {"id": 2
After (valid):
{"items": [{"id": 1}, {"id": 2}]}
An extra opening bracket was added.
One more [ than ] leaves one level open at the end of the text.
Before (fails):{"a": [[1, 2]}
After (valid):
{"a": [[1, 2]]}
A nested object was pasted without its closing brace.
Hand-edited or merged files often lose a } when a block is moved.
Before (fails):{"user": {"name": "Ana", "tags": ["a"]}, "ok": true
After (valid):
{"user": {"name": "Ana", "tags": ["a"]}, "ok": true}
How to fix it in Python
- Read the line and column in the JSONDecodeError. Treat them as the place the parser gave up, then look at the lines just before it.
- Paste the text into the Validator to see the error highlighted, or into the Formatter to see the indentation break where a bracket is missing.
- Count the openers and closers in each nested block. Every [ needs a ] and every { needs a }, in the reverse order they were opened.
- If the text ends early, check where it came from. Compare the length with what you expected and look for a size limit, a timeout or a token cap.
- For text you cannot fix by hand, run it through the Repair tool, which closes open brackets and reports what it changed.
- Parse again with json.loads() and confirm the result is the shape you expect.
import json
def close_brackets(text):
# Appends missing closers when the text was cut off at the end.
# Returns None if the brackets are mismatched in the middle.
stack = []
in_string = False
escaped = False
for ch in text:
if in_string:
if escaped:
escaped = False
elif ch == "\\":
escaped = True
elif ch == '"':
in_string = False
elif ch == '"':
in_string = True
elif ch in "{[":
stack.append("}" if ch == "{" else "]")
elif ch in "}]":
if not stack or stack[-1] != ch:
return None
stack.pop()
if in_string:
return None
return text + "".join(reversed(stack))
def parse(text):
try:
return json.loads(text)
except json.JSONDecodeError as err:
print(f"Invalid JSON at line {err.lineno}, column {err.colno}: {err.msg}")
fixed = close_brackets(text)
if fixed is None:
raise
return json.loads(fixed)
Variants of the message
| Message | Cause | Fix |
|---|---|---|
| Expecting ',' delimiter | A bracket is missing or wrong, so the next character cannot follow the value. | Check the brackets just before the reported position. |
| Expecting value | The text ends or a value is absent after a comma or colon. | Complete the value or remove the stray comma. |
| Expecting property name enclosed in double quotes | A key is missing or an object has a trailing comma. | Quote the key or remove the trailing comma. |
| Extra data | A complete value was followed by more text, often an extra closing bracket. | Remove the extra } or ], or split multiple documents. |
| Unterminated string starting at | Text was cut off inside a string. | Close the string, then the brackets. |
| Expecting ':' delimiter | A key has no colon after it, often after a bracket was lost. | Add the colon and value. |
Related errors
- JSONDecodeError: Expecting ',' delimiter: How to Fix It in Python
- JSONDecodeError: Extra data: How to Fix It in Python
- Unterminated string in JSON: How to Fix It in Python
- Trailing comma in JSON: How to Fix It in Python
- Fix Python JSON Errors: json.loads() Decode Errors and How to Repair Them
Key takeaways
- Python reports a missing bracket as JSONDecodeError, usually Expecting ',' delimiter.
- The line and column show where parsing stopped, which can be after the real mistake.
- Every [ needs a ] and every { needs a }, closed in reverse order.
- Truncated input from networks, logs or LLMs is a common source of missing closers.
- Validate with the Validator and repair with the Repair tool when hand-fixing is slow.
FAQ
Why does Python not say 'missing bracket'?
The json module reports what the parser saw, not what the author meant. It cannot know which bracket you forgot, so it names the token it expected, such as a comma delimiter.
Is the reported position where the bracket is missing?
The position is where the parser stopped, not where the bracket went missing. The missing bracket can sit earlier in the text, so check the lines before the reported line.
Can I fix truncated JSON automatically?
You can append the missing closers, as in the code above, and the result may parse. The data lost at the cut is gone, so check that the repaired document still holds what you need.
Does the json module accept a missing bracket in any mode?
No. json.loads() has no lenient mode for unbalanced brackets, and the JSON standard requires each array and object to be closed.
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