Common JSON Errors and How to Fix Them

Learn how to identify, understand, and fix JSON errors with practical examples and browser-based debugging tools.

Developer debugging JSON syntax errors using browser-based tools

1. What Makes JSON Invalid?

JSON (JavaScript Object Notation) is a lightweight data-interchange format defined by the strict rules of RFC 8259. Because it is designed to be easily read by machines, it has a very strict syntax. A single missing comma or unquoted key makes the entire JSON payload invalid, causing parsers to fail.

A valid JSON structure consists of keys and values, arrays, strings, numbers, booleans, and null values. Keys must always be enclosed in double quotes. Let's look at a simple valid JSON object:

{
  "name": "John",
  "age": 25,
  "active": true
}
          

In this example, every key is wrapped in double quotes, key-value pairs are separated by commas, and the final item does not end with a trailing comma. Adhering to these strict rules prevents parser failures in your applications.

2. Why JSON Errors Happen

JSON syntax errors usually happen during manual editing, copy-pasting code, or due to bad API configurations. Let's look at the most common causes of JSON errors:

  • Manual Editing (40%): Forgetting commas, using single quotes, or adding comments when editing config files manually.
  • API Configuration Mistakes (25%): Systems concatenating strings manually instead of using standard JSON encoding libraries.
  • Formatting Issues (20%): Copy-pasting raw payloads across editors that convert standard quotes to curved "smart" quotes.
  • Encoding Failures (15%): Mismatched character sets that corrupt special characters in keys or string values.

3. 25 Common JSON Errors

Error 1

Missing Comma Between Key-Value Pairs

❌ Broken JSON
{ "name": "John" "age": 25 }
🟒 Correct JSON
{ "name": "John", "age": 25 }

Why it fails: The parser expects a comma as a separator between object properties. Without it, the parser fails, reading the next key as an invalid syntax token.

Prevention Tip: Use a JSON editor that auto-inserts commas or run your payload through a formatter to highlight missing separators.

πŸ› οΈ Recommended Tool: JSON Formatter →
Error 2

Trailing Comma After the Last Element

❌ Broken JSON
{ "name": "John", "age": 25, }
🟒 Correct JSON
{ "name": "John", "age": 25 }

Why it fails: A trailing comma tells the parser that another item follows. When the parser finds a closing brace instead, it fails.

Prevention Tip: Remember that JSON does not support trailing commas, unlike standard JavaScript arrays or objects.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 3

Using Single Quotes Instead of Double Quotes

❌ Broken JSON
{ 'name': 'John' }
🟒 Correct JSON
{ "name": "John" }

Why it fails: The RFC 8259 specification requires keys and string values to be wrapped in double quotes. Single quotes will trigger parse errors.

Prevention Tip: Use an automated formatter tool to replace single quotes with double quotes automatically.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 4

Unquoted Object Keys

❌ Broken JSON
{ name: "John" }
🟒 Correct JSON
{ "name": "John" }

Why it fails: While JavaScript allows unquoted keys, JSON requires all keys to be strings wrapped in double quotes.

Prevention Tip: Always wrap keys in double quotes, even when writing simple config files.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 5

Extra Closing Curly Brace

❌ Broken JSON
{ "name": "John" }}
🟒 Correct JSON
{ "name": "John" }

Why it fails: The parser finishes reading the object at the first closing brace. The second brace is read as extra text outside the document, triggering an error.

Prevention Tip: Use a JSON formatter to check that all braces and brackets match correctly.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 6

Missing Closing Curly Brace

❌ Broken JSON
{ "name": "John"
🟒 Correct JSON
{ "name": "John" }

Why it fails: The parser reaches the end of the file before finding the closing brace, triggering an 'unexpected end of input' error.

Prevention Tip: Enable brace-matching in your code editor to make sure all opened braces are closed.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 7

Missing Closing Square Bracket for Arrays

❌ Broken JSON
[ {"id": 1}, {"id": 2}
🟒 Correct JSON
[ {"id": 1}, {"id": 2} ]

Why it fails: The parser reaches the end of the file before finding the closing bracket of the array.

Prevention Tip: Always format arrays with proper indentation to easily check that the closing bracket is present.

πŸ› οΈ Recommended Tool: JSON Formatter →
Error 8

Extra Closing Square Bracket

❌ Broken JSON
[ {"id": 1} ]]
🟒 Correct JSON
[ {"id": 1} ]

Why it fails: The parser reads the second closing bracket as invalid text outside the array scope.

Prevention Tip: Run your payload through a formatter to check that all braces and brackets match.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 9

Unescaped Control Characters in Strings

❌ Broken JSON
{ "path": "C:\Program Files\app" }
🟒 Correct JSON
{ "path": "C:\\Program Files\\app" }

Why it fails: Backward slashes (\) are used for escape sequences (like \n or \t). An unescaped backslash causes the parser to fail.

Prevention Tip: Always use double backslashes (\\) to escape backward slashes in strings.

πŸ› οΈ Recommended Tool: JSON Viewer →
Error 10

Double Commas Separating Fields

❌ Broken JSON
{ "name": "John",, "age": 25 }
🟒 Correct JSON
{ "name": "John", "age": 25 }

Why it fails: The parser reads the second comma as an empty or missing element, triggering a syntax error.

Prevention Tip: Avoid manual editing mistakes by using a formatter to clean up duplicate characters.

πŸ› οΈ Recommended Tool: JSON Formatter →
Error 11

Missing Colon Separator

❌ Broken JSON
{ "name" "John" }
🟒 Correct JSON
{ "name": "John" }

Why it fails: The colon (:) is required to separate keys from their values. Without it, parsing fails.

Prevention Tip: Check that every key is followed by a colon before its value.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 12

Invalid Case for Boolean Values

❌ Broken JSON
{ "active": True }
🟒 Correct JSON
{ "active": true }

Why it fails: JSON specifies booleans must be lowercase (`true` or `false`). Uppercase variants (like Python's `True`) trigger errors.

Prevention Tip: Always write booleans in lowercase when working with JSON.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 13

Using Undefined Values

❌ Broken JSON
{ "data": undefined }
🟒 Correct JSON
{ "data": null }

Why it fails: JSON does not support `undefined`. Use `null` to represent empty or missing values.

Prevention Tip: Replace `undefined` values with `null` when preparing data payloads.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 14

Using NaN (Not a Number)

❌ Broken JSON
{ "result": NaN }
🟒 Correct JSON
{ "result": null }

Why it fails: The JSON standard only supports real numbers. Using `NaN` will trigger parse errors.

Prevention Tip: Convert `NaN` values to `null` before encoding your data to JSON.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 15

Using Infinity Values

❌ Broken JSON
{ "limit": Infinity }
🟒 Correct JSON
{ "limit": null }

Why it fails: JSON does not support `Infinity`. Use numeric limits or `null` instead.

Prevention Tip: Check that your numerical values are real numbers before parsing.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 16

Using Comments Inside JSON Files

❌ Broken JSON
{ // User name "name": "John" }
🟒 Correct JSON
{ "name": "John" }

Why it fails: JSON is a data format and does not support comments (like `//` or `/* */`). Adding them makes the JSON invalid.

Prevention Tip: Keep comments in your documentation, not in your JSON configuration files.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 17

Duplicate Keys in the Same Object

❌ Broken JSON
{ "name": "John", "name": "Alice" }
🟒 Correct JSON
{ "name": "Alice" }

Why it fails: While some parsers ignore duplicate keys and keep the last value, others will fail, leading to inconsistent behavior in your apps.

Prevention Tip: Check that all keys within the same object are unique.

πŸ› οΈ Recommended Tool: JSON Viewer →
Error 18

Invalid Unicode Characters

❌ Broken JSON
{ "char": "\x41" }
🟒 Correct JSON
{ "char": "\u0041" }

Why it fails: JSON requires Unicode escape sequences to follow the `\uXXXX` format. Hex formats like `\x` will trigger errors.

Prevention Tip: Use valid Unicode characters or escape sequences in your strings.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 19

Improper Nesting of Objects and Arrays

❌ Broken JSON
{ "user": [ "name": "John" ] }
🟒 Correct JSON
{ "user": { "name": "John" } }

Why it fails: Key-value pairs must reside in objects `{}`. Placing them directly inside arrays `[]` is invalid.

Prevention Tip: Check your nesting structure to ensure objects and arrays are used correctly.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 20

Mixed Array Item Separators

❌ Broken JSON
[1; 2; 3]
🟒 Correct JSON
[1, 2, 3]

Why it fails: JSON arrays must use commas as item separators. Semicolons (;) are not supported.

Prevention Tip: Always use commas to separate items in an array.

πŸ› οΈ Recommended Tool: JSON Formatter →
Error 21

Using Curved "Smart" Quotes

❌ Broken JSON
{ β€œname”: β€œJohn” }
🟒 Correct JSON
{ "name": "John" }

Why it fails: Copying text from some text editors can convert straight double quotes to curved "smart" quotes, which the parser reads as invalid characters.

Prevention Tip: Write code in a text editor designed for programming, and avoid rich text editors.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 22

Extra Characters After the JSON Block

❌ Broken JSON
{ "name": "John" } var active = true;
🟒 Correct JSON
{ "name": "John" }

Why it fails: The parser expects the document to end after the closing brace of the main object. Extra text outside this block triggers an error.

Prevention Tip: Keep only the JSON block in your file, and remove any extra code.

πŸ› οΈ Recommended Tool: JSON Beautifier →
Error 23

Malformed Array Declarations

❌ Broken JSON
[ "a",, "b" ]
🟒 Correct JSON
[ "a", "b" ]

Why it fails: Mismatched or duplicate commas inside an array create empty elements, causing the parser to fail.

Prevention Tip: Check your arrays for extra commas before parsing.

πŸ› οΈ Recommended Tool: JSON Formatter →
Error 24

Broken API Response Returning HTML

❌ Broken JSON
<html>500 Server Error</html>
🟒 Correct JSON
{ "status": "error", "message": "500 Server Error" }

Why it fails: APIs that experience internal server errors can return HTML pages instead of the expected JSON data, triggering a 'unexpected token <' error.

Prevention Tip: Check the response headers and HTTP status codes before parsing the data payload.

πŸ› οΈ Recommended Tool: JSON Validator →
Error 25

Incomplete JSON Payload

❌ Broken JSON
{ "user": { "name": "John"
🟒 Correct JSON
{ "user": { "name": "John" } }

Why it fails: Network interruptions or truncated API logs can leave documents unfinished, resulting in mismatched braces.

Prevention Tip: Verify that the entire payload has downloaded successfully before parsing.

πŸ› οΈ Recommended Tool: JSON Beautifier →

4. Step-by-Step JSON Debugging Workflow

Avoid guessing when fixing JSON errors. Follow this structured debugging process to identify and resolve issues quickly:

βš™οΈ JSON Debugging Workflow
Copy JSON
Validate
Format Code
Locate Error
Fix Syntax
Re-Validate

Step 1: Copy the Original JSON

Always work on a copy of your JSON payload. Keep a backup of the original data in a separate file to prevent accidental data loss during debugging.

Step 2: Validate the JSON

Paste the copy into our local JSON Validator. This runs syntax checks in your browser memory to highlight errors without uploading your data to remote servers.

Step 3: Beautify the JSON

Run your JSON through a Formatter or Beautifier. Indentation and line breaks make missing commas, unquoted keys, and mismatched braces much easier to locate.

Step 4: Identify the Exact Error

Review the error message from the validator. Common parser messages include:

  • Unexpected token: Usually indicates single quotes or missing commas right before the highlighted character.
  • Unexpected end of JSON input: Typically caused by a missing closing brace or bracket.
  • Expected property name: Unquoted keys or trailing commas before closing braces.
  • Invalid character: Mismatched encoding or smart quotes in keys or strings.

Step 5: Correct the Syntax

Fix one error at a time. Make a single edit, run the validator again, and repeat the process until all syntax issues are resolved.

Step 6: Test the JSON

Run a final validation check on the corrected JSON to verify that the payload parses correctly in your application.

5. Debugging API Responses

Many JSON errors originate from APIs rather than manually edited files. Network issues, authentication failures, or server crashes can corrupt data payloads before they reach your app.

If you see a parsing error like `Unexpected token <`, it usually means the server failed and returned an HTML error page (starting with `<!DOCTYPE html>`) instead of the expected JSON data.

Always check the HTTP status code (like 200, 401, or 500) and verify that the `Content-Type` header is set to `application/json` before parsing the response body.

6. JSON Formatter vs JSON Validator

Formatters and validators perform different tasks. Use this comparison table to choose the right tool for your debugging needs:

Feature JSON Formatter JSON Validator
Beautifies code structure βœ… Yes ❌ No
Finds syntax errors ❌ No βœ… Yes
Adds standard indentation βœ… Yes ❌ No
Validates RFC 8259 syntax ❌ No βœ… Yes
Improves code readability βœ… Yes ❌ No

We recommend using both tools together. Format the JSON first to make it readable, and then use the validator to locate and fix syntax issues.

7. IDE vs Browser-Based JSON Tools

Choose between IDE plugins and browser-based tools based on your workflow needs:

Feature Browser-Based Tools IDE Plugins
Installation required ❌ No (Instant access) βœ… Yes (Plugin install)
Processing location πŸ”’ Local memory (100% private) πŸ’» Local computer
System impact ⚑ Zero slowdown ⏳ Can slow down IDE start times
Automatic updates βœ… Yes ❌ No (Manual updates)

Browser-based tools are ideal for quick debugging, working on shared computers, remote work, or when you want to avoid bloated IDE extensions.

8. JSON Validation Checklist

Check these items before parsing or saving your JSON configuration files:

  • Quotes Check: Are all keys and string values wrapped in double quotes?
  • Commas Check: Are elements separated by commas, with no trailing comma at the end?
  • Braces Match: Do all opening braces and brackets have matching closing pairs?
  • Value Check: Are you using valid JSON types (no `undefined` or `NaN`)?
  • Comments Check: Have you removed all comments from the file?
  • Character Encoding: Is the file saved using UTF-8 encoding?

9. Frequently Asked Questions

The most common JSON error is a missing comma between key-value pairs. Other frequent issues include trailing commas, using single quotes instead of double quotes, missing braces, invalid escape characters, and malformed arrays. A JSON validator quickly identifies these syntax problems.
Format your JSON using a beautifier to locate the highlighted token. This error is usually caused by unquoted keys, single quotes, or missing commas right before the token.
JSON requires strict syntax rules. Any missing commas, unquoted keys, single quotation marks, comments, or mismatched brackets will make the entire file invalid.
Paste your JSON block into our local JSON Validator. It runs validation checks entirely in your browser memory for 100% privacy.
Formatting adds indentation and spacing to make code readable. Validation runs syntax checks to find and highlight errors.
No. The official JSON specification (RFC 8259) does not support comments (like // or /* */). Adding them will make the JSON invalid.
The JSON standard specifies that keys and string values must be enclosed in double quotes. Single quotes will trigger parse errors.
Check the response headers and HTTP status codes. If you see 'Unexpected token <', the API is returning HTML (like an error page) instead of JSON.
Placing a comma after the last key-value pair or array item causes a trailing comma error. The parser expects another item and fails.
Paste the code into a formatter to locate formatting errors. Fix them one by one, replacing single quotes and adding missing commas.
Unescaped control characters or backward slashes (\) inside strings trigger escape errors. Use double backslashes (\\) to escape them.
No. JSON only supports string, number, object, array, boolean, and null values. Using 'undefined' will trigger a parsing error.
While some parsers allow duplicate keys, others overwrite previous values or fail, leading to inconsistent behavior in applications.
Developers should use local, browser-based validators, formatters, and minifiers to format and test code blocks quickly and privately.
Run minified JSON through a Formatter or Beautifier to add standard indentation, line breaks, and spacing.
Yes, especially for quick troubleshooting, working on shared systems, or when you want to avoid bloated IDE extensions.
Format the JSON to display nesting levels clearly. Mismatched braces are easier to locate when the nesting is properly indented.
According to the JSON specification, JSON data exchanged between systems must be encoded in UTF-8 to prevent character mapping errors.
Use standard libraries (like JSON.stringify in JS or json_encode in PHP) to generate JSON instead of manually concatenating strings.
We recommend using our JSON Formatter to format code, JSON Validator to check syntax, and JSON Minifier to compress files for API payloads.

Standard JSON Code Patterns

Use these standard JSON patterns as references when creating or validating data structures:

1. Valid Object

{
  "id": 1,
  "name": "Alice",
  "active": true
}
          

A simple object containing numeric, string, and boolean values with correct comma separation.

2. Valid Array

[
  {
    "id": 1
  },
  {
    "id": 2
  }
]
          

An array of objects with correct comma separation and enclosing square brackets.

3. Nested Object

{
  "user": {
    "name": "John",
    "address": {
      "city": "London"
    }
  }
}
          

A nested hierarchy where each child object is enclosed in curly braces.

4. API Response

{
  "status": "success",
  "data": {
    "users": [
      {
        "id": 1,
        "name": "Alice"
      }
    ]
  }
}
          

A standard API response object containing status info and nested array arrays.

Featured Free JSON Utilities

Related Insights & Guides