10 Common JSON Errors and How to Fix Them

Learn how to fix 10 common JSON errors, including missing commas, invalid quotes, trailing commas, and parsing failures. Explore practical examples and debugging tips from full stack development and DevOps workflows.

sumit magar
sumit magarDeveloper and technical writer
Updated July 9, 2026

Imagine you are a full stack developer working on a React application with a Node.js backend. You send a request to your API, expecting a list of users, but instead, the server returns an error. You check the browser console, inspect the network request, and discover that the JSON data contains a small syntax mistake.

Now imagine a similar problem during deployment. Your application works on your local machine, but a JSON configuration file fails to load on the production server. A missing comma or an extra trailing comma can be enough to stop the application from starting.

These problems are common in web development. JSON is easy to read and widely used, but it follows strict syntax rules. In this guide, we will explore 10 common JSON errors, understand why they happen, and learn how to fix them with practical examples.

1. Using Single Quotes Instead of Double Quotes

One of the most common JSON errors is using single quotes around property names or string values. Developers who work with JavaScript objects often make this mistake because JavaScript allows single quotes in object values.

Incorrect JSON:

{
  'name': 'Sumit',
  'role': 'Developer'
}

This is not valid JSON because JSON requires double quotes around property names and string values.

Correct JSON:

{
  "name": "Sumit",
  "role": "Developer"
}

How to fix it: Always use double quotes for JSON property names and string values. Remember that a JavaScript object literal and a JSON document are not exactly the same thing.

2. Forgetting Commas Between Properties

JSON uses commas to separate properties inside an object and values inside an array. Forgetting a comma can cause a parsing error. Imagine you are creating a configuration file for your Node.js application.

Incorrect JSON:

{
  "host": "localhost"
  "port": 5000
}

The parser cannot identify where the first property ends and the next one begins.

Correct JSON:

{
  "host": "localhost",
  "port": 5000
}

How to fix it: Add a comma between properties, except after the last property in an object. When debugging a large JSON file, check the line immediately before the error message because the actual mistake may be there.

3. Adding a Trailing Comma

This error often appears when developers manually edit configuration files or copy JavaScript objects into a JSON file.

Incorrect JSON:

{
  "name": "My API",
  "port": 5000,
}

The comma after 5000 is not allowed because it appears after the final property.

Correct JSON:

{
  "name": "My API",
  "port": 5000
}

How to fix it: Remove the comma after the last property or array element. Standard JSON does not support trailing commas, even though some programming languages allow them in their own object or array syntax.

4. Forgetting Double Quotes Around Property Names

In JavaScript, you can write an object without putting quotes around property names in many situations. JSON has a stricter rule.

Incorrect JSON:

{
  name: "Sumit",
  age: 25
}

Correct JSON:

{
  "name": "Sumit",
  "age": 25
}

How to fix it: Put double quotes around every property name. This is especially important when exporting data from JavaScript applications or writing JSON configuration files by hand.

5. Using Comments Inside JSON

While working on a project, you may want to add a comment explaining why a setting exists. However, standard JSON does not support comments.

Incorrect JSON:

{
  // API server port
  "port": 5000
}

The // comment makes the document invalid JSON.

Correct JSON:

{
  "port": 5000
}

How to fix it: Remove comments from standard JSON files. If you need documentation, keep it in a separate README file or use a format such as YAML when the application supports it.

For example, many DevOps tools use YAML for configuration because it supports comments and is convenient for human-edited settings.

6. Mismatched Braces and Brackets

JSON uses curly braces for objects and square brackets for arrays. Every opening bracket must have a matching closing bracket of the correct type.

This becomes harder to manage when you work with deeply nested API responses.

Incorrect JSON:

{
  "user": {
    "name": "Sumit",
    "skills": ["JavaScript", "Node.js"]
  ]
}

The user object is closed with a square bracket instead of a curly brace.

Correct JSON:

{
  "user": {
    "name": "Sumit",
    "skills": ["JavaScript", "Node.js"]
  }
}

How to fix it: Check that every { has a matching } and every [ has a matching ]. Use an editor with bracket matching or a JSON formatter to make nested structures easier to inspect.

7. Using Invalid Escape Characters in Strings

JSON strings cannot contain certain unescaped characters. For example, a backslash introduces an escape sequence, so a Windows file path can cause problems when written incorrectly.

Incorrect JSON:

{
  "path": "C:\newfolder\app"
}

Here, \n is interpreted as a newline escape rather than as the literal characters in the folder name.

Correct JSON:

{
  "path": "C:\\newfolder\\app"
}

How to fix it: Use \\ when you need a literal backslash. JSON also supports escape sequences such as \", \n, and \t. Other invalid escape sequences can cause parsing errors. This is useful when storing file paths, Windows directory locations, or text containing quotation marks.

8. Using Undefined, NaN, or Infinity

JavaScript supports values such as undefined, NaN, and Infinity. Standard JSON does not. This can become a problem when a backend prepares data and attempts to serialize it for an API response.

Incorrect JSON:

{
  "username": undefined,
  "score": NaN,
  "balance": Infinity
}

These values are not valid JSON values.

Correct JSON:

{
  "username": null,
  "score": null,
  "balance": null
}

How to fix it: Replace unsupported values with valid JSON values, such as null, or handle them before serialization.

Be careful: JSON.stringify() does not treat all these values in the same way. For example, undefined object properties are omitted, while NaN and Infinity are serialized as null. Validate your data before sending it to another service.

9. Sending a JavaScript Object Instead of a JSON String

Sometimes the problem is not the JSON syntax itself but how data is sent between the frontend and backend. For example, a React application sends a request to an Express API. The backend expects JSON, but the frontend sends a JavaScript object without serializing it.

Example of sending JSON correctly:

const user = {
  name: "Sumit",
  role: "Developer"
};

fetch("/api/users", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(user) });

The JSON.stringify() method converts the JavaScript object into a JSON string that can be sent in the request body.

On the Express side, the application commonly uses:

app.use(express.json());

This middleware parses incoming JSON request bodies when the request has the appropriate content type.

How to fix it: Serialize JavaScript objects with JSON.stringify() before sending them as JSON request bodies. On the server, configure the appropriate JSON parser and check that the request headers and body match what the API expects.

10. Parsing Invalid JSON Without Error Handling

Even if your application normally receives valid JSON, external APIs, uploaded files, and user input can contain malformed data.

Consider this example:

const response = '{"name": "Sumit", "age": }';

const data = JSON.parse(response);

The JSON string is invalid because the age property has no value. Calling JSON.parse() throws a SyntaxError.

If the error is not handled, it can interrupt the current operation and cause an API request or application workflow to fail.

A safer approach:

try {
  const data = JSON.parse(response);
  console.log(data);
} catch (error) {
  console.error("Invalid JSON:", error.message);
}

How to fix it: Validate incoming JSON and handle parsing errors. In production applications, return an appropriate error response, log useful diagnostic information, and avoid exposing sensitive internal details to users.

For DevOps engineers, this is also important when scripts read JSON configuration files, deployment metadata, or API responses. A failed parse should be detected before the script performs important deployment steps.

How to Find and Fix JSON Errors Faster

When JSON fails to load, avoid changing random lines until the error disappears. Follow a simple debugging process instead.

  1. Read the error message: Note the reported line and position, if available.

  2. Check the surrounding lines: Missing commas and quotation marks often cause errors near the next property.

  3. Validate the document: Use a JSON parser or an online JSON validator.

  4. Format the data: Indentation makes nested objects and arrays easier to inspect.

  5. Test the actual workflow: If the JSON is used by an API or deployment tool, test it with that tool as well.

You can use a JSON formatter to make JSON easier to read and inspect. If you need the same data in YAML for a supported configuration workflow, you can also use the site's JSON to YAML converter. Remember that valid JSON does not automatically mean valid application configuration. A file can pass JSON parsing and still contain a missing environment variable, an incorrect port, or a value that violates your application's expected schema.

Conclusion

JSON errors may look small, but they can interrupt API requests, break configuration loading, and delay deployments. The most common problems include missing commas, incorrect quotation marks, trailing commas, mismatched brackets, invalid escape characters, and unsupported values.

As a full stack developer, learn to distinguish JavaScript objects from JSON strings and handle parsing errors properly. As a DevOps engineer, validate configuration files and API responses before using them in deployment scripts.

A reliable workflow is simple: write valid JSON, validate it early, handle errors safely, and test it in the environment where it will actually run. These habits can save time during development and prevent avoidable production issues.

sumit magar
man behind

sumit magar

Full Stack Developer and Technical Writer building practical tools, software, and web apps that simplify complex technical tasks and improve developer productivity.