Missing bracket in JSON: How to Fix It in JavaScript
JSON.parse() fails when a [ or { has no matching closing bracket. See the causes, the errors V8 shows, and how to fix it in JavaScript.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →A missing bracket means a [ or { was opened and never closed, or was closed with the wrong character. JSON.parse() stops at the first spot where the text no longer fits the JSON grammar and throws a SyntaxError.
What “Missing bracket in JSON” means
The parser found a closing bracket that does not match the one it expected, or the text ended while a bracket was still open. JSON requires every [ to end with ] and every { to end with }. JavaScript has no error with the exact text "Missing bracket". V8 reports it as "Expected ',' or ']' after array element", "Expected ',' or '}' after property value", or "Unexpected end of JSON input", usually with a position.
Causes and the fix for each
An array is never closed
The ] is missing, so the parser reaches } while it still expects another element or a ].
Before (fails):{"items": [1, 2, 3}
After (valid):
{"items": [1, 2, 3]}
An object is never closed
The final } is missing, so the text ends while the object is still open.
Before (fails):{"user": {"id": 1, "name": "Ana"}
After (valid):
{"user": {"id": 1, "name": "Ana"}}
The wrong closing bracket is used
A ] closes an object, or a } closes an array. The types must match.
Before (fails):{"tags": ["a", "b"}
After (valid):
{"tags": ["a", "b"]}
The response was cut off
A network error, a size limit, or a streaming read can stop the body halfway, so the closing brackets never arrive.
Before (fails):{"rows": [{"id": 1}, {"id": 2
After (valid):
{"rows": [{"id": 1}, {"id": 2}]}
A bracket was deleted during manual editing or a bad merge
Copy and paste, or a merge conflict, can drop one line that held the only closing bracket.
Before (fails):{"a": [{"b": 1}, {"c": 2}
}
After (valid):
{"a": [{"b": 1}, {"c": 2}]
}
How to fix it in JavaScript
- Read the error message and note the position. V8 prints it as "at position N". The real mistake is at or just before that character.
- Paste the text into the Validator to see the line and column of the first mismatch.
- Run the Formatter on the text. Indentation makes an unclosed array or object easy to see, because the nesting stops lining up.
- Check that each opening bracket has a closing bracket of the same type, and that they close in reverse order of opening.
- If the text came from a network call, log its length and last 50 characters. A body that ends mid-value was truncated, so fix the source and not the text.
- If you cannot fix the source, paste the text into the Repair tool to add the missing brackets, then check that the result holds the data you expected.
function parseJson(text) {
try {
return { ok: true, value: JSON.parse(text) };
} catch (err) {
return { ok: false, error: err.message, hint: bracketHint(text) };
}
}
function bracketHint(text) {
const stack = [];
const pairs = { '}': '{', ']': '[' };
let inString = false;
for (let i = 0; i < text.length; i++) {
const ch = text[i];
if (inString) {
if (ch === '\\') i++;
else if (ch === '"') inString = false;
continue;
}
if (ch === '"') inString = true;
else if (ch === '{' || ch === '[') stack.push(ch);
else if (ch === '}' || ch === ']') {
if (stack.pop() !== pairs[ch]) return 'Mismatched ' + ch + ' at position ' + i;
}
}
return stack.length ? 'Unclosed: ' + stack.join('') : 'Brackets balance';
}
const result = parseJson('{"items": [1, 2, 3}');
console.log(result);
Variants of the message
| Message | Cause | Fix |
|---|---|---|
| Expected ',' or ']' after array element in JSON at position N | An array was closed with the wrong character or not closed | Add ] after the last element, or remove the stray character. |
| Expected ',' or '}' after property value in JSON at position N | An object was not closed, or a ] closed it | Add } after the last property. |
| Unexpected end of JSON input | The text ended while a bracket was still open, or the text is empty | Check for truncation and add the missing closing brackets. |
| Unexpected token } in JSON at position N | A } appeared where a value was expected, often after a comma | Remove the trailing comma or add the missing value. |
| Unexpected non-whitespace character after JSON at position N | An extra closing bracket or a second document follows the first | Remove the extra bracket or split the documents. |
Related errors
- JSON Missing Bracket Error: How to Find and Fix It
- JavaScript JSON.parse() Errors: What They Mean and How to Fix Them
- Invalid JSON Meaning: What It Is and How to Fix It
- Trailing comma in JSON: How to Fix It in JavaScript
- Unterminated string in JSON: Fix JSON.parse() in JavaScript
Key takeaways
- Every [ needs a ] and every { needs a }, closed in reverse order.
- The error position is where parsing stopped, so check the text just before it.
- V8 words the problem as "Expected ',' or ']'" or "Unexpected end of JSON input".
- A truncated response is a common cause, so check the source before editing the text.
- Use the Validator to locate the error and the Repair tool to fix it.
FAQ
Why does JavaScript not say "missing bracket"?
The parser reports what it saw, not what you meant. It sees a character it did not expect, or the end of the text, and names that. The missing bracket is the usual reason behind it.
Is the position in the error always the exact spot of the mistake?
No. It is where the parser gave up. The missing bracket is often earlier, so look at the lines just before that position.
Can JSON.parse() fix a missing bracket for me?
No. JSON.parse() only accepts valid JSON and throws on anything else. You need to correct the text first, by hand or with a repair tool.
Why do I get "Unexpected end of JSON input" with an empty response?
An empty string has no value, so the parser reaches the end before it finds one. Check the response status and body before you call JSON.parse().
Do single quotes or comments cause bracket errors?
They cause their own errors, but they can shift where the parser reports a problem. JSON allows only double-quoted strings and has no comments.
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