Tutorial · 6 min read

How to Fix Invalid JSON from API Response

Ever copy a JSON response from an API, paste it into your code, and get a parser error? You're not alone. Broken JSON from APIs is one of the most common frustrations for developers. This guide covers the 6 most common errors and how to fix them — or just use our JSON Repair Tool to handle them automatically.

1. Trailing Commas in Objects and Arrays

JavaScript allows trailing commas. JSON does not. This is the #1 cause of broken JSON from API responses.

{
  "name": "Alice",
  "age": 30,   // ← trailing comma
}

Fix: Remove the comma after the last element. If you have multiple objects, only the last one should omit the trailing comma. Paste it into a repair tool and it handles this automatically.

2. Single Quotes Instead of Double Quotes

Some APIs or hand-written configs use single quotes. JSON spec requires double quotes for both keys and string values.

{
  'name': 'Alice',
  'age': 30
}

Fix: Replace all single quotes with double quotes — but be careful not to touch apostrophes inside string values. A proper repair tool handles this correctly by parsing context, not doing a blind string replace.

3. Unquoted Property Keys

JavaScript object literals allow unquoted keys. JSON does not. This is common in hand-written configs or legacy API responses.

{
  name: "Alice",
  age: 30
}

Fix: Wrap every key name in double quotes. The repair tool automatically wraps all unquoted property names.

4. Missing or Mismatched Brackets

Truncated responses, copy-paste errors, or incomplete logs can leave JSON with missing closing brackets.

{
  "users": [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Bob"}
  ]
}

Fix: Count your opening and closing braces / brackets. They must match exactly. The repair engine auto-inserts missing closing delimiters.

5. Comments Inside JSON

JSON does not support comments. Period. But many developers add them, especially when extracting JSON from code or configuration files.

{
  // User profile
  "name": "Alice",    /* inline comment */
  "age": 30
}

Fix: Strip all comments before parsing. The repair tool removes both // and /* */ comments automatically.

6. Broken JSON from ChatGPT / Claude / LLMs

Large language models often wrap JSON in markdown code blocks, use mixed quotes, add trailing commas, or include explanatory text around the JSON.

Here's the JSON you requested:
```json
{
  "name": "Alice",
  'age': 30,
}
```

Fix: Strip markdown wrappers, fix quotes, remove trailing commas. The tool handles all of these in one pass — just paste the raw LLM output.

Try the Free JSON Repair Tool

Paste broken JSON and fix it instantly. No signup, no server upload.

Fix JSON Now →

Best Practices to Avoid Broken JSON

Frequently Asked Questions

How to fix invalid JSON from an API response?

Copy the raw response and paste it into the JSON Repair Tool. It automatically fixes trailing commas, single quotes, unquoted keys, missing brackets, and comments in one click.

Why does my JSON API response have trailing commas?

Some API implementations generate JSON using JavaScript object literals instead of proper JSON serialization, which allows trailing commas. JSON spec requires no trailing comma after the last element.

Can I repair broken JSON from ChatGPT or Claude?

Yes. LLM outputs often have markdown code block wrappers, mixed quotes, trailing commas, and extra text. Just paste the raw output and the repair tool handles all of these.

Is it safe to paste my API response into an online JSON repair tool?

Yes — this tool is 100% browser-based. Your data never leaves your computer. No server storage, no tracking, no uploads. All processing happens locally in your browser.

What is the difference between JSON Repair and JSON Validate?

Validation tells you what is wrong. Repair fixes it. JSONXX has both: use the JSON Editor for validation, and the Repair tool for automatic fixes.

Can I export repaired JSON to CSV or Excel?

Once repaired, use JSON to CSV or JSON to Excel to convert the repaired output to spreadsheet format.

Looking for more guides? See the full JSONXX How To index.