DEV Community

Cover image for 15 Common JSON Errors and How to Fix Them (With Real Examples)
unixly
unixly

Posted on

15 Common JSON Errors and How to Fix Them (With Real Examples)

If you work with APIs, configuration files, or frontend applications, you've almost certainly encountered a JSON parsing error.

Sometimes the error message is obvious.

Sometimes it's completely misleading.

The frustrating part is that a tiny syntax mistake can prevent an entire application from working.

Over the years, I've noticed that most JSON issues fall into the same handful of categories. This article covers the ones I see most often, along with examples of how to fix them.


1. Missing Comma

One of the most common mistakes.

❌ Invalid

{
  "name": "John"
  "age": 30
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John",
  "age": 30
}
Enter fullscreen mode Exit fullscreen mode

Every key-value pair must be separated by a comma.


2. Trailing Comma

Many programming languages allow trailing commas.

JSON does not.

❌ Invalid

{
  "name": "John",
  "age": 30,
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John",
  "age": 30
}
Enter fullscreen mode Exit fullscreen mode

3. Using Single Quotes

JSON only supports double quotes.

❌ Invalid

{
  'name': 'John'
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John"
}
Enter fullscreen mode Exit fullscreen mode

4. Unquoted Property Names

Property names must always be enclosed in double quotes.

❌ Invalid

{
  name: "John"
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John"
}
Enter fullscreen mode Exit fullscreen mode

5. Missing Closing Brace

A surprisingly common mistake when editing large JSON files.

❌ Invalid

{
  "name": "John",
  "age": 30
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John",
  "age": 30
}
Enter fullscreen mode Exit fullscreen mode

6. Missing Closing Bracket

Arrays need closing brackets.

❌ Invalid

{
  "skills": [
    "Java",
    "Python"
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "skills": [
    "Java",
    "Python"
  ]
}
Enter fullscreen mode Exit fullscreen mode

7. Invalid Boolean Values

JSON uses lowercase values.

❌ Invalid

{
  "active": True
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "active": true
}
Enter fullscreen mode Exit fullscreen mode

The same applies to false and null.


8. Invalid Number Format

Numbers shouldn't be quoted unless they're intended to be strings.


{
  "price": "150"
}
Enter fullscreen mode Exit fullscreen mode


{
  "price": 150
}
Enter fullscreen mode Exit fullscreen mode

Use strings only when the value is actually text.


9. Comments Inside JSON

JSON doesn't support comments.

❌ Invalid

{
  // User Name
  "name": "John"
}
Enter fullscreen mode Exit fullscreen mode

Remove comments before parsing.


10. Extra Comma Inside Arrays

❌ Invalid

[
  "HTML",
  ,
  "CSS"
]
Enter fullscreen mode Exit fullscreen mode

✅ Correct

[
  "HTML",
  "CSS"
]
Enter fullscreen mode Exit fullscreen mode

11. Incorrect Nesting

Braces and brackets must match.

❌ Invalid

{
  "user": [
    "name": "John"
  ]
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "user": {
    "name": "John"
  }
}
Enter fullscreen mode Exit fullscreen mode

12. Invalid Escape Characters

Backslashes need escaping.

❌ Invalid

{
  "path": "C:\Users\Admin"
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "path": "C:\\Users\\Admin"
}
Enter fullscreen mode Exit fullscreen mode

13. Empty Value

Every key requires a valid value.

❌ Invalid

{
  "name":
}
Enter fullscreen mode Exit fullscreen mode

Use a proper value.

{
  "name": ""
}
Enter fullscreen mode Exit fullscreen mode

or

{
  "name": null
}
Enter fullscreen mode Exit fullscreen mode

14. Mixing JSON with JavaScript Objects

Developers often copy JavaScript objects directly.

const user = {
  name: "John",
  age: 30
}
Enter fullscreen mode Exit fullscreen mode

That's valid JavaScript.

It isn't valid JSON.

JSON requires quoted property names.


15. Copying API Responses Without Validation

This one isn't a syntax mistake—it's a workflow mistake.

It's common to copy a large API response into an editor and assume it's valid.

Instead, validate it first.

A formatter immediately tells you:

  • where the error occurred
  • which line failed
  • whether the JSON is valid
  • how the document should be structured

That saves a surprising amount of debugging time.


My Go-To Workflow for Debugging JSON

Whenever something doesn't parse, I follow the same process.

Step 1 — Confirm it's actually JSON

Sometimes logs, emails, or API responses look like JSON but aren't.

Instead of guessing, I first paste the content into a JSON Detector.

It quickly identifies whether the text is valid JSON or something else.

👉 https://www.unixlytools.com/tools/json-detector/


Step 2 — Format and Validate

Once I know it's JSON, I format it using a JSON formatter.

Proper indentation makes problems much easier to spot, especially in nested objects.

I usually use this free JSON Formatter & Validator:

👉 https://www.unixlytools.com/tools/json-formatter/

It validates the JSON while formatting it, making missing commas, unmatched braces, and syntax errors much easier to identify.


Step 3 — Fix the Reported Error

Once the parser points to the problematic line, fixing the issue usually takes seconds instead of manually scanning hundreds of lines.


Final Thoughts

JSON is intentionally strict.

That strictness is what makes it reliable across programming languages and APIs, but it also means tiny mistakes can have outsized consequences.

The good news is that most JSON parsing issues are easy to fix once you know what to look for.

Instead of hunting through hundreds of lines of text, make validation part of your workflow.

Your future self—and your teammates—will thank you.

Happy debugging! 🚀

Top comments (0)