Back to Blog
TroubleshootingMarch 1, 20264 min read

Common JSON Errors and How to Fix Them

A practical guide to the most frequent JSON syntax errors developers encounter, with clear explanations and fixes for each one.

Why JSON Parsing Fails

JSON has a strict syntax specification. Unlike JavaScript objects, JSON does not allow trailing commas, single quotes, comments, or unquoted keys. Even a single character out of place will cause a parse error. Here are the most common mistakes and how to fix them.

Trailing Commas

A trailing comma after the last element in an object or array is the most common JSON error. JavaScript allows this, but JSON does not. Always remove the comma after the last item.

// Invalid - trailing comma
{"name": "John", "age": 30,}

// Valid
{"name": "John", "age": 30}

Single Quotes Instead of Double Quotes

JSON requires double quotes for strings and keys. Single quotes are not valid. If you are copying data from JavaScript code, make sure to convert all single quotes to double quotes.

// Invalid - single quotes
{'name': 'John'}

// Valid
{"name": "John"}

Missing Quotes on Keys

Every key in a JSON object must be enclosed in double quotes. Unquoted keys work in JavaScript but are invalid in JSON.

// Invalid - unquoted key
{name: "John"}

// Valid
{"name": "John"}

Comments in JSON

JSON does not support comments. Neither // single-line nor /* multi-line */ comments are allowed. If you need comments in your configuration, consider using YAML instead, or use a "_comment" key as a workaround.

// Invalid - comment in JSON
{
  // This is a name
  "name": "John"
}

// Workaround
{
  "_comment": "This is a name",
  "name": "John"
}

Unescaped Special Characters

Strings in JSON must escape certain characters: double quotes (\")), backslashes (\\), and control characters like newlines (\n) and tabs (\t). Unescaped special characters will cause parsing failures.

Try Our JSON Tools

Format, validate, minify, and convert JSON data instantly.