DEV Community

ToolBench
ToolBench

Posted on

10 JSON Mistakes That Break APIs (And How to Avoid Them)

JSON has become the standard format for exchanging data between applications. Whether you're building REST APIs, integrating third-party services, or working with frontend frameworks like React, Angular, or Vue, you'll interact with JSON almost every day.

Despite its simple syntax, even small mistakes in JSON can cause API requests to fail, configuration files to break, or applications to crash.

In this article, we'll go through 10 common JSON mistakes developers make and how to avoid them.


1. Forgetting Double Quotes Around Property Names

JSON requires every property name to be enclosed in double quotes.

❌ Incorrect

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

✅ Correct

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

Many developers accidentally write JavaScript object syntax instead of valid JSON.


2. Using Single Quotes

JSON only supports double quotes.

❌ Incorrect

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

✅ Correct

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

3. Leaving a Trailing Comma

Trailing commas are common in JavaScript but are invalid in JSON.

❌ Incorrect

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

✅ Correct

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

4. Missing Commas Between Properties

A missing comma is one of the most common reasons JSON validation fails.

❌ Incorrect

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

✅ Correct

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

5. Invalid Data Types

JSON supports only these data types:

  • String
  • Number
  • Boolean
  • Object
  • Array
  • null

Trying to include unsupported values like functions or undefined makes the JSON invalid.

❌ Incorrect

{
  "name": "John",
  "value": undefined
}
Enter fullscreen mode Exit fullscreen mode

Instead, use:

{
  "name": "John",
  "value": null
}
Enter fullscreen mode Exit fullscreen mode

6. Sending Numbers as Strings

Sometimes APIs expect a number, but developers accidentally send a string.


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


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

This small mistake can cause validation errors on the server.


7. Invalid Nested Objects

Complex JSON often becomes difficult to read.

Instead of writing everything on one line:

{"user":{"address":{"city":"London","zip":"12345"}}}
Enter fullscreen mode Exit fullscreen mode

Format it properly:

{
  "user": {
    "address": {
      "city": "London",
      "zip": "12345"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Readable JSON is much easier to debug.


8. Mixing Arrays and Objects

Arrays use square brackets.

Objects use curly braces.

Incorrect structure:

{
  "skills": {
    "Java",
    "C#"
  }
}
Enter fullscreen mode Exit fullscreen mode

Correct structure:

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

9. Not Validating JSON Before Sending It

Many API errors happen because invalid JSON is sent to the server.

Before calling an API:

  • Validate your JSON.
  • Format it for readability.
  • Check the data types.
  • Ensure all required fields exist.

This simple habit can save a lot of debugging time.


10. Ignoring API Documentation

Even if your JSON is valid, it may still fail if it doesn't match the API's expected structure.

For example:

Expected:

{
  "email": "john@example.com"
}
Enter fullscreen mode Exit fullscreen mode

Sent:

{
  "emailAddress": "john@example.com"
}
Enter fullscreen mode Exit fullscreen mode

The JSON is valid, but the API doesn't recognize the property.

Always compare your request with the API documentation.


Quick Checklist Before Sending JSON

✅ Property names use double quotes

✅ No trailing commas

✅ Valid data types

✅ Arrays use []

✅ Objects use {}

✅ Required properties are included

✅ Numbers are not sent as strings

✅ JSON is validated


Final Thoughts

Most JSON-related issues aren't caused by complex bugs—they're caused by tiny syntax mistakes that are easy to overlook.

By validating your JSON, formatting it for readability, and following API documentation carefully, you can avoid hours of unnecessary debugging.

What JSON mistake has cost you the most time? Share your experience in the comments—your story might help another developer avoid the same issue.


## Explore More Developer Tools

If you regularly work with JSON, APIs, formatting, encoding, decoding, or data conversion, check out ToolBenchApp:

👉 https://toolbenchapp.com/

ToolBenchApp is a growing collection of free browser-based developer tools designed to simplify everyday development tasks. Whether you need to format JSON, decode JWTs, compare text, generate UUIDs, or convert data between formats, the goal is simple: help developers save time and stay focused on building great software.

If there's a tool you'd like to see added, I'd love to hear your suggestions!

Top comments (0)