Prescosoft

Troubleshooting Guide

Common JSON Syntax Errors and How to Fix Them

Six errors that break JSON — with real examples and the exact fix for each. Written for developers who just need their JSON to parse.

1 Trailing Commas

A trailing comma after the last item in an array or object is the single most common JSON error. JSON doesn't allow it — unlike JavaScript object literals, which do.

Wrong:

{
  "name": "Alice",
  "role": "engineer",  // ← trailing comma
}

Fixed:

{
  "name": "Alice",
  "role": "engineer"
}

This error frequently happens when copying JS object syntax into a .json file, or when adding/removing items from a list. A JSON formatter will catch this immediately with a line number.

2 Unquoted Property Names

All JSON property names must be wrapped in double quotes. Unquoted keys (allowed in JavaScript) cause parsing to fail.

Wrong:

{
  name: "Alice",
  age: 30
}

Fixed:

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

This often happens when hand-writing JSON or copying console output (which uses JS syntax). The fix is mechanical: quote every key.

3 Single Quotes Instead of Double Quotes

JSON only accepts double quotes (") for strings and keys. Single quotes (') are invalid.

Wrong:

{
  'name': 'Alice',
  'city': 'London'
}

Fixed:

{
  "name": "Alice",
  "city": "London"
}

Why this happens: Python and JavaScript both allow single-quoted strings. When developers switch between languages and manually construct JSON, single quotes creep in. A find-and-replace won't always work safely — use a JSON formatter which can re-quote everything correctly.

4 Using JavaScript Values (undefined, functions, etc.)

JSON only supports six value types: strings, numbers, booleans, null, arrays, and objects. Using undefined, NaN, Infinity, or functions will break parsing.

Wrong:

{
  "score": NaN,
  "active": undefined,
  "value": Infinity
}

Fixed:

{
  "score": null,
  "active": false,
  "value": null
}

Numbers in JSON cannot have leading zeros (01 is invalid — use 1) and must be base-10. This error often surfaces when serializing JavaScript objects that contain undefined properties.

5 Adding Comments

JSON does not support comments. Both // and /* */ style comments cause syntax errors.

Wrong:

{
  // User configuration
  "name": "Alice",
  "port": 8080 /* default port */
}

Fixed:

{
  "name": "Alice",
  "port": 8080
}

If you need documentation in your data file, consider moving comments to a separate file or switching to a format that supports them natively, such as JSON5 (which extends JSON with comments) or YAML.

6 Unescaped Special Characters in Strings

Certain characters must be escaped inside JSON string values: backslash (\), double quote ("), newline (\n), tab (\t), and carriage return (\r).

Wrong:

{
  "path": "C:\Users\alice",
  "note": "She said "hi""
}

Fixed:

{
  "path": "C:\\Users\\alice",
  "note": "She said \"hi\""
}

This error is common when JSON contains file paths (Windows backslashes) or user-generated content (quotes in text). When building JSON programmatically, use your language's built-in serializer (JSON.stringify(), json.dumps()) to handle escaping automatically.

Quick Reference: Common JSON Syntax Errors

Error Example Fix
Trailing comma"a": 1,Remove the final comma
Unquoted key{ name: "x" }Add double quotes around key
Single quotes'value'Replace with double quotes
Invalid value typeundefined, NaNUse null, false, or a number
Comments// noteRemove comments entirely
Unescaped charsC:\pathEscape backslashes and quotes

Debug JSON Privately — No Uploads

Paste broken JSON, get instant syntax highlighting with line numbers. Your data never leaves your browser — critical when your JSON contains API keys, auth tokens, or configuration secrets.

100% client-side. No account. No tracking.

Open JSON Formatter

Frequently Asked Questions

Why does JSON not allow trailing commas?

JSON was designed as a strict data interchange format (RFC 8259), not a programming language syntax. Trailing commas create ambiguity in parsing and were excluded to keep the specification simple and unambiguous. JavaScript objects allow trailing commas, which is why this error is common when copying JS object literals into JSON files.

Can I use single quotes in JSON?

No. JSON requires double quotes for all strings and property names. Single quotes will cause a syntax error. This is one of the most common errors when developers write JSON by hand, since JavaScript (and Python) both accept single quotes for strings.

What's the difference between JSON and JavaScript objects?

JSON is a text-based data format with strict syntax rules: property names must be quoted, only double quotes are allowed, trailing commas are invalid, and values are limited to strings, numbers, booleans, null, arrays, and objects. JavaScript objects are more permissive — they allow unquoted keys, functions as values, single quotes, and trailing commas.

How do I find where a JSON error is?

Use a JSON validator that shows line and column numbers for errors, such as the Prescosoft JSON Formatter which highlights the exact line where the syntax breaks. The error message will tell you what's wrong (e.g., "Unexpected token } at line 5 column 3"). Always start debugging from the first error — fixing it often resolves cascading errors reported on later lines.

Can JSON have comments?

No. The JSON specification (RFC 8259) does not support comments. Any text outside of string values will cause a parsing error. If you need documentation in your JSON, use a separate schema file, a .jsonc file (used by VS Code for config), or a format like JSON5 or YAML that supports comments natively.

How do I validate JSON quickly?

Paste your JSON into a client-side JSON formatter. It validates syntax instantly, highlights errors with line numbers, and never sends your data to a server — important if your JSON contains API keys, tokens, or sensitive configuration.

Related Guides