Common JSON Syntax Errors and How to Fix Them

JSON 常见语法错误及修复方法

When calling APIs, editing config files, or processing data, a single tiny JSON syntax error causes the entire parse to fail. Error messages are often cryptic, and finding the actual error location is time-consuming.

Learn the 5 most common JSON syntax error categories and the standard spec. Combined with Suried Tools' precise error location feature, you can fix any JSON issue in seconds.

01 Error 1: Trailing Commas

The JSON standard (RFC 8259) explicitly states: no comma is allowed after the last key-value pair in an object or the last element in an array. This is the most common mistake when converting JavaScript to JSON.

While JavaScript allows trailing commas, JSON does not. A parser encountering a comma immediately followed by } or ] flagged as a syntax error.

Fix: Remove the comma after the last element. Suried Tools pinpoints the exact position of the extra comma.

02 Error 2: Unquoted Keys

In JavaScript objects, keys can be unquoted (e.g., { name: "Alice" }), but JSON requires all keys to be wrapped in double quotes (e.g., { "name": "Alice" }).

This error is especially common when writing JSON manually or copying from JavaScript object literals. The parser reports "expected string" or "unexpected token" errors.

03 Error 3: Single Quotes Instead of Double Quotes

JSON string values and keys must use double quotes (") — single quotes (') are not allowed. This is a mistake Python developers make especially often, since Python treats single and double quotes equivalently.

Replacing all single quotes with double quotes fixes this. Note that double quotes inside string content need backslash escaping (\").

Suried Tools can automatically detect and suggest replacing single quotes with double quotes.

04 Error 4: Mismatched Brackets or Braces

In complex nested JSON, missing or extra ] or } characters are extremely common. Error messages for these issues usually appear at the end of the file, but the actual error may be in the middle.

The solution is using a formatter for automatic indentation — opening and closing brackets align at each nesting level, making missing brackets obvious. Suried Tools' error messages attempt to infer the most likely position of the missing bracket.

05 Error 5: Unescaped Special Characters in Strings

Several characters must be escaped in JSON strings: double quotes (\"), backslashes (\\), newlines (\n), tabs (\t), and others. Including these characters directly in strings causes parse failures.

Especially error-prone scenarios include: file paths with backslashes (like Windows paths C:\Users\...), HTML content with double quotes, and multi-line text with newline characters.

  • \" — double quote
  • \\ — backslash
  • \n — newline
  • \t — tab
  • \u0000 — Unicode escape

FAQ

Can I write comments in JSON?

Standard JSON does not support comments of any kind (no // or /* */). If you need a configuration file with comments, use JSON5 or JSONC (JSON with Comments). Many modern tools (like VS Code's settings.json) use JSONC.

Why doesn't JSON support NaN and Infinity?

JSON is designed as a cross-language data interchange format, and NaN/Infinity are not universally supported across all programming languages. JSON numbers allow only standard decimal digit format. Use strings or null as alternatives for these values.

Does the order of JSON keys matter?

Per the JSON standard, key order in objects should have no semantic significance. However, in practice, some signature verification algorithms depend on key ordering. If you encounter signature mismatch issues, try sorting keys alphabetically.

How should I handle dates and times in JSON?

JSON has no native date/time type. Dates are typically represented as ISO 8601 format strings (e.g., "2024-01-15T08:30:00Z"). This is the most universal approach and is correctly parsed by virtually all languages and frameworks.

Can Suried Tools auto-fix JSON syntax errors?

For common simple errors (like trailing commas, single quotes), the tool offers auto-fix suggestions. For structural issues (like severe bracket mismatches), manual fixing based on error hints is recommended to ensure data semantic correctness.

🐛

Try the Tool Now

Learn the 5 most common JSON syntax error categories and the standard spec. Combined with Suried Tools' precise error location feature, you can fix any JSON issue in seconds.

TOOLS.SURIED.COM