JSON (JavaScript Object Notation) powers almost everything on the modern web—REST APIs, webhook payloads, WordPress block configurations, package.json manifests, and Google SEO application/ld+json structured data. Because JSON looks nearly identical to JavaScript object literals, developers routinely copy JavaScript snippets straight into JSON files and hit cryptic parser crashes like Unexpected token or Expected property name or '}'.
Unlike forgiving HTML browsers that guess what you meant, JSON parsers follow the strict RFC 8259 specification: one misplaced comma or single quote breaks the entire payload. Learning the seven errors below—and keeping a fast local validator handy—cuts debugging time from twenty minutes down to five seconds.
The 7 Most Common JSON Syntax Errors (With Before & After Fixes)
1. Trailing Commas After the Last Item
JavaScript, TypeScript, and Python allow trailing commas at the end of arrays and objects because they make Git diffs cleaner. Strict JSON forbids them completely.
// INVALID JSON:
{
"brand": "SmartUtilDeck",
"tools": 15,
}
// VALID JSON:
{
"brand": "SmartUtilDeck",
"tools": 15
}
2. Single Quotes Instead of Double Quotes
In JavaScript you can freely write 'name' or "name". In JSON, both object keys and string values must use straight double quotes ("). Curly “smart quotes” pasted from Word documents or chat apps (“ and ”) also break JSON parsers immediately.
// INVALID: {'status': 'ok'}
// VALID: {"status": "ok"}
3. Unquoted Object Keys
JavaScript objects allow bare property names like { active: true }. JSON requires every key to be enclosed in double quotes: { "active": true }.
4. Comments Left Inside JSON Files
Standard JSON has no comment syntax—neither // single-line nor /* block */ comments are allowed. Only JSONC (used in VS Code configs) supports comments. If you need documentation inside strict JSON, store a dedicated "_comment": "..." string property instead.
5. Unescaped Newlines, Tabs, or Inner Quotes
Literal line breaks or unescaped double quotes inside a JSON string immediately terminate the string early and throw a syntax error. Always escape internal newlines as\n, tabs as \t, backslashes as \\, and literal double quotes inside strings as \":
// INVALID:
{
“message”: “Line 1
Line 2 with “quotes””
}
// VALID:
{
“message”: “Line 1\nLine 2 with \”quotes\””
}
6. Leading Zeros or Non-Standard Number Literals
JSON numbers cannot begin with a leading zero (except 0.x decimals), and special JavaScript values like NaN, Infinity, or undefined are invalid in JSON. Store postal codes, phone numbers, and zero-padded IDs like "0042" as quoted strings rather than numbers.
7. Missing Closing Brackets or Braces in Nested Payloads
When editing deeply nested API responses or multi-question FAQPage schema scripts by hand, deleting one item often leaves an unmatched [ or {. Indenting the payload cleanly makes missing closures jump off the screen immediately.
Quick Debugging Reference Table
| Parser Error Message | Most Likely Cause | Fastest Fix |
|---|---|---|
Expected double-quoted property name |
Trailing comma or unquoted key | Delete comma before } or wrap key in "..." |
Unexpected token ' |
Single quotes used around key/value | Replace single quotes with straight double quotes |
Unterminated string in JSON |
Raw newline or unescaped " inside text |
Replace raw line break with \n and quote with \" |
Unexpected end of JSON input |
Missing final } or ] |
Format with 2-space indent to spot unclosed level |
How to Format, Validate, Sort & Minify JSON Privately
Never paste API tokens, customer webhook payloads, or private configuration secrets into cloud JSON websites that log requests on remote servers. Open our browser-based JSON Formatter, Validator & Minifier instead:
- Paste your raw or broken JSON string into the input box.
- Click Format (2 Spaces) or Format (4 Spaces). If there is a syntax error, an instant red banner highlights the parser error message; if valid, the formatted output displays total byte size.
- Need to compare two large config files? Click Sort Keys to recursively sort all object keys alphabetically (A–Z) while keeping array order untouched.
- Ready to store or send over an API? Click Minify to strip unnecessary whitespace cleanly.
Real-World JSON Debugging Workflows for Web Developers
Handling UTF-8 Encoding & Invisible BOM Characters
Sometimes a JSON file looks 100% syntactically valid to the naked eye—matching quotes, zero trailing commas, balanced braces—yet a parser still rejects line 1 character 1! In Windows editors like classic Notepad, saving files as “UTF-8 with BOM” prepends three invisible bytes (EF BB BF) at the very start of the file. Always save JSON configuration files as UTF-8 (without BOM).
Objects vs Arrays: Picking the Right Structure
API beginners frequently confuse when to wrap items in curly braces { ... } (unordered key-value object) versus square brackets [ ... ] (ordered list array). Use arrays when sequence matters or you have multiple homogeneous records (like FAQ questions, invoice line items, or search results), and use objects when looking up named attributes by key (like "subtotal", "currency", or "author").
Testing API & Schema Payloads Before Deploying
- Validate Structure First: Run every hand-edited configuration or JSON-LD block through our JSON Formatter & Validator so trailing commas never slip into production HTML.
- Compare Diffs Cleanly: Before committing large JSON translation or config updates to Git, use Sort Keys so rearranged properties align alphabetically across commits.
- Check Webhook Checksums: When testing signed JSON webhook payloads locally, pair clean minified JSON output with our SHA-256 Hash Generator to verify payload digests without exposing secret strings online.
Worked Example: Fixing a Real Broken FAQ Schema JSON-LD Block
Consider this realistic snippet copied from a blog template that fails validation for three separate reasons—a trailing comma on the first question, single quotes on the second answer, and an unescaped quote inside the text:
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{ "@type": "Question", "name": "Is it free?", "acceptedAnswer": { "@type": "Answer", "text": "Yes, 100% free." } },
{ "@type": "Question", "name": "How fast?", "acceptedAnswer": { "@type": "Answer", "text": "Instant "browser" speed." } }
]
}
Running raw snippets through a local formatter catches every syntax snag before Googlebot or your API consumers ever encounter it.
Frequently Asked Questions
Does JSON support trailing commas in JavaScript JSON.parse()?
No. Native JSON.parse() strictly rejects trailing commas across every browser and Node.js runtime.
Why did my JSON-LD Schema fail Google Rich Results Test?
Usually due to a trailing comma after the last FAQ object or an unescaped double quote inside an answer string. Validate any custom JSON-LD inside our JSON Formatter—or build clean error-free markup directly with the Schema Markup Generator.
Is Boolean true/false capitalized in JSON?
No. Booleans must be lowercase (true / false) and null must be lowercase (null), without quotes.
How can I tell the difference between a JSON array and a JSON object quickly?
Objects always start with curly braces { and store named "key": value pairs separated by colons, while arrays always start with square brackets [ and hold an ordered comma-separated list of values. Mixing up closing } and ] brackets is one of the fastest syntax errors caught by indenting with 2 spaces.
Why do some API logs fail JSON validation when copied from a terminal?
Terminal logs frequently truncate long responses with ..., insert line-wrapping artifacts, or print JavaScript object inspection syntax (unquoted keys and single quotes) rather than genuine serialized JSON. Formatting and validating payloads locally immediately exposes any non-JSON characters before you paste them into config files or automated tests. Always verify raw strings with our JSON Formatter and check byte size cleanly before committing changes to production repositories.