Fix JSON Error: Missing Bracket or Brace

When your JSON is missing a ] or }, the parser reaches the end of input before it expects to. Here's how to find the missing bracket and fix the structure.

JSONTech TeamMarch 1, 20255 min read

The Error Message

Missing brackets and braces typically produce one of these errors:

SyntaxError: Unexpected end of JSON input
SyntaxError: Expected ',' or ']' in JSON at position 52
SyntaxError: Expected ',' or '}' in JSON at position 73
JSON.parse: unexpected end of data at line 6 column 1

The "Unexpected end of JSON input" message is the classic sign of a missing closing bracket or brace — the parser ran out of characters while it was still inside a structure.

What Causes This Error

1. Missing Closing Brace on an Object

// ❌ Broken — no closing }
{
  "name": "Alice",
  "age": 30
// ✅ Fixed
{
  "name": "Alice",
  "age": 30
}

2. Missing Closing Bracket on an Array

// ❌ Broken — no closing ]
{
  "tags": ["javascript", "json", "parsing"
}
// ✅ Fixed
{
  "tags": ["javascript", "json", "parsing"]
}

3. Mismatched Brackets in Nested Structures

With deeply nested JSON, it's easy to close with the wrong type of bracket or to miss one level entirely.

// ❌ Broken — inner object missing its closing }
{
  "users": [
    {
      "name": "Alice",
      "address": {
        "city": "New York"
    }
  ]
}
// ✅ Fixed — added missing } for address object
{
  "users": [
    {
      "name": "Alice",
      "address": {
        "city": "New York"
      }
    }
  ]
}

4. Truncated JSON

Sometimes JSON is cut off mid-stream — for example, when a network response is interrupted, a log file gets truncated, or a database field has a character limit. The parser sees the beginning of a valid structure but never reaches the end.

// ❌ Truncated — response cut off
{"users":[{"name":"Alice","email":"alice@exam

Truncated JSON usually can't be fixed by simply adding brackets — the data itself is incomplete. You'll need to re-fetch the full response or check your data source.

How to Count Brackets

A quick way to diagnose the problem: count the opening and closing brackets separately.

  • Every { needs exactly one matching }.
  • Every [ needs exactly one matching ].
  • If the counts don't match, you know how many are missing. Most code editors have a "find all" feature — search for { and note the count, then search for } and compare.

How to Fix It Step by Step

  1. Count brackets and braces.Compare opening vs closing counts to identify what's missing.
  2. Use indentation as a guide. Properly formatted JSON makes the structure visible. If your JSON is minified, run it through a formatter first.
  3. Work from the inside out. Start with the deepest nested level and make sure each object and array is properly closed before moving to the outer levels.
  4. Use an editor with bracket matching.Click on any bracket in VS Code and it highlights its matching partner. If no partner highlights, that's your culprit.
  5. Validate after each fix.Add one bracket at a time and re-validate to make sure you're placing it in the right spot.

Prevention Tips

  • Always format JSON with proper indentation before editing by hand — flat or minified JSON makes bracket errors invisible.
  • Use an editor that shows bracket matching and auto-closes brackets as you type.
  • When dealing with API responses, check the Content-Length header to ensure you received the complete response.
  • For large JSON documents, consider using a streaming parser that can report exactly where it lost track of the structure.

Fix it automatically: Paste your broken JSON into our JSON Repair tool — it handles this error and dozens more. Or validate your JSON first with our JSON Validator.

Related Tools