JSON & Data4 min readUpdated 2026-11-18

Common JSON Mistakes and How to Fix Them

Troubleshoot trailing commas, quotes, comments, and escaping bugs in JSON.

JavaScript object literals are forgiving; strict JSON (RFC 8259) is not. One stray comma or single quote copied from a JavaScript tutorial breaks an entire configuration file or rejects an API request with SyntaxError: Unexpected token. Most JSON parse failures come from the exact same seven mistakes—once you know how to recognize them, debugging takes seconds.

1. Trailing commas after the last item

TypeScript, Python, and modern JavaScript encourage trailing commas because they produce cleaner git diffs. Standard JSON forbids them in both objects and arrays. Removing the final comma before } or ] resolves more config failures than almost any other edit.

Invalid vs. Valid (Trailing Comma)
// Invalid JSON
{
  "port": 3000,
  "tags": ["api", "v2",],
}

// Valid JSON
{
  "port": 3000,
  "tags": ["api", "v2"]
}

2. Single quotes or unquoted property names

Every key and every string value in JSON must be wrapped in ASCII double quotes ("). Single quotes ('), curly typographic quotes copied from Slack or Notion, and bare keys like { debug: true } are rejected immediately by JSON.parse().

Invalid vs. Valid (Quoting Rules)
// Invalid: bare key & single quotes
{
  env: 'production'
}

// Valid: double quotes for keys and strings
{
  "env": "production"
}

3. Comments and unsupported JavaScript values

JSON has no comment syntax—neither // nor /* ... */ exists in RFC 8259. (While tools like VS Code support JSONC internally for settings files, standard parsers reject comments.) Likewise, JavaScript primitives such as undefined, NaN, Infinity, functions, and Date instances are invalid. Replace missing values with null and represent dates as ISO 8601 strings.

4. Unescaped newlines, tabs, and backslashes in strings

Inside a JSON string, raw control characters (ASCII 0x00 through 0x1F, including literal line breaks and tab stops) are illegal, and Windows file paths containing single backslashes fail because \ begins an escape sequence. Use \n for line breaks, \" for literal quotes, and \\ for literal backslashes.

Invalid vs. Valid (Escaping Backslashes & Line Breaks)
// Invalid: unescaped Windows path & raw newline
{
  "path": "C:\users\dev",
  "note": "line one
line two"
}

// Valid JSON
{
  "path": "C:\\users\\dev",
  "note": "line one\nline two"
}

5. Double-escaped logs and hidden UTF-8 BOMs

Two subtle errors produce confusing parser messages even when brackets look balanced:

  • Double-encoded JSON strings: Structured logging pipelines often serialize an object once into JSON, then serialize that string inside a log message field, leaving "{\"status\":200}". Paste those payloads into our JSON Unescape tool to strip the extra layer cleanly.
  • UTF-8 Byte Order Mark (BOM): An invisible \uFEFF character at byte zero—often inserted by older Windows editors—causes Unexpected token at line 1, column 1 even though the file starts with {.
  • Duplicate keys: RFC 8259 recommends unique member names inside objects, though parsers rarely throw on duplicates—instead, the last key silently overwrites earlier values. Compare suspect configs using JSON Diff when values mysteriously vanish.

6. Numeric formatting quirks and precision loss

JSON numbers follow strict rules under RFC 8259: leading zeros like 07 or 02138 are invalid syntax (postal codes and octal modes must be stored as quoted strings), explicit leading plus signs like +42 are forbidden, and hexadecimal literals such as 0xFF are not supported. Even when JSON is syntactically valid, keep 64-bit database IDs or financial totals as strings when JavaScript clients parse them, because IEEE 754 floats silently round integers above 9,007,199,254,740,991 (Number.MAX_SAFE_INTEGER).

Common error clues and immediate fixes
Error SymptomLikely CauseQuick Fix
Unexpected token } or ]Trailing comma or extra bracketRemove comma before closing brace/bracket
Unexpected token at pos 0UTF-8 BOM, HTML error page, or single quoteStrip BOM or verify response is not HTML
Unterminated stringUnescaped newline or quote inside stringEscape with \n or \"
Expected double-quoted propertyBare JS object key or comment lineQuote keys with " and remove // comments
Unexpected numberLeading zero like 05 or leading + signQuote ZIP codes as strings or drop leading 0/+
Debug top-down from the first syntax error only

One missing quote or stray comma early in a file triggers dozens of cascading errors further down. Fix the very first line reported by the validator, re-run validation, and ignore downstream bracket mismatches until that top line passes.

Whenever an API payload or config file fails, drop it into the FormatFlow JSON Validator or JSON Formatter & Repair tool to inspect the exact line and column without sending credentials to external servers. New to the format? Read our primer on what JSON is and how its types work.

Try the FormatFlow Tools Mentioned Above

All tools run privately in browser memory with zero file uploads.