My Debug Notebook: 12 Common JSON Errors and How I Fixed Them
After getting roasted by my tech lead for the 5th JSON-related bug, I started keeping a notebook. Here are the 12 most common JSON errors I've encountered.
又被组长批了。"这个 JSON 解析错误你怎么又犯了?"
Fine. I started keeping a bug notebook. Every JSON error I encounter goes in. After 6 months, here are the 12 most common ones — with fixes.
Error 1: Trailing Commas
{ "name": "John", "age": 30, } // ❌ Invalid
{ "name": "John", "age": 30 } // ✅ Valid
JSON does NOT allow trailing commas. JavaScript does. That's why it works in Node.js but fails in JSON.parse().
Error 2: Single Quotes
{ 'name': 'John' } // ❌ Invalid
{ "name": "John" } // ✅ Valid
JSON requires double quotes. Always.
Error 3: Unquoted Keys
{ name: "John" } // ❌ Invalid (works in JS object literal)
{ "name": "John" } // ✅ Valid JSON
Error 4: Comments
{ "name": "John" /* this is a comment */ } // ❌ Invalid
{ "name": "John" } // ✅ No comments allowed in JSON
JSON does NOT support comments. Use JSONC (JSON with Comments) if you need them.
Error 5: NaN and Infinity
{ "value": NaN } // ❌ Invalid
{ "value": Infinity } // ❌ Invalid
{ "value": null } // ✅ Use null instead
Error 6: Date Objects
{ "date": new Date() } // ❌ Not valid JSON
{ "date": "2024-02-18T00:00:00Z" } // ✅ ISO 8601 string
Error 7: Undefined Values
{ "value": undefined } // ❌ Not valid JSON
{ "value": null } // ✅ Use null
// Or just omit the key entirely
Error 8: Circular References
const obj = { name: "John" };
obj.self = obj; // Circular!
JSON.stringify(obj); // TypeError: Converting circular structure to JSON
Fix: Use a replacer function or a library like flatted.
Error 9: Encoding Issues
{ "text": "Hello â€" World" } // ❌ Mojibake
{ "text": "Hello — World" } // ✅ Proper UTF-8
Always ensure UTF-8 encoding throughout your pipeline.
Error 10: Large Numbers
{ "id": 9007199254740993 } // ❌ Precision loss in JavaScript
{ "id": "9007199254740993" } // ✅ Use string for large numbers
JavaScript's Number.MAX_SAFE_INTEGER is 2^53 - 1. Beyond that, precision is lost.
Error 11: BOM Character
{ "name": "John" } // ❌ BOM at start causes parse error
{ "name": "John" } // ✅ No BOM
UTF-8 BOM (Byte Order Mark) is invisible but breaks JSON parsers.
Error 12: Mixed Content Types
{ "items": [1, "two", null, {"four": 4}] } // ✅ Valid but fragile
Arrays with mixed types are valid JSON but cause runtime errors when you assume all elements are the same type.
My Debugging Workflow
- Paste the JSON into a JSON Formatter — it highlights the exact error location
- Check for the 12 errors above
- Validate against a JSON Schema to catch structural issues
- Compare with expected output using JSON Compare
Validate and fix your JSON instantly with our free JSON Formatter — highlights errors, beautifies output, and validates structure.
Explore More Developer Tools
Discover more tools and tutorials in this category
Related Articles
Troubleshooting Node.js Errors: The Complete Debugging Guide
Hello friends! Don't worry about Node.js errors anymore! I will explain everything simply...
XML to JSON and Back: The Complete Conversion Guide for Legacy Systems
Migrating from XML APIs to JSON? Or need to integrate with a legacy SOAP service? Here's everything you need to know about converting between the two.
Scaling JSON at Enterprise Level: Lessons from Processing Billions of Requests
When you're handling billions of API requests daily, JSON parsing becomes a critical bottleneck. Here's what we learned optimizing JSON pipelines at scale.