JSON Parse Error: Common Causes and How to Fix Them

A JSON parse error means a program tried to read JSON data but could not understand it in the expected JSON format. Usually the syntax is invalid, the JSON is incomplete, the response is not actually JSON, or the program is parsing the wrong value.

By Archana Bhandari ยท

A quick example

INVALID JSON: the trailing comma after the final property makes this invalid. A parser expecting standard JSON will reject it. Remove that comma to fix the data.

{
  "name": "Rahul",
  "city": "Dehradun",
}

The fixed JSON

VALID JSON: this has the same data without the trailing comma.

{
  "name": "Rahul",
  "city": "Dehradun"
}

What is a JSON parse error?

Parsing is software reading text and turning it into structured data it can work with. A program can parse the valid JSON below and then use name as Rahul and age as 28. If the text does not follow the expected syntax, parsing fails.

{
  "name": "Rahul",
  "age": 28
}

What causes a JSON parse error?

Common causes include invalid syntax, missing or trailing commas, missing quotes, single quotes, incorrect brackets, incomplete JSON, unexpected characters, bad escape characters, empty responses, and trying to parse HTML or an object that is already parsed.

  • Invalid JSON syntax or incomplete data.
  • An API returning HTML, a login page, or an error page instead of JSON.
  • An empty response body when code expected JSON.
  • Passing a JavaScript object to JSON.parse() instead of a JSON string.

1. Trailing comma

INVALID JSON: JSON does not permit a comma after its final property.

{
  "name": "Rahul",
  "age": 28,
}

Trailing comma fixed

VALID JSON: remove the last comma.

{
  "name": "Rahul",
  "age": 28
}

2. Missing comma

INVALID JSON: a comma must separate these two properties.

{
  "name": "Rahul"
  "age": 28
}

Missing comma fixed

VALID JSON: add the separator.

{
  "name": "Rahul",
  "age": 28
}

3. Single quotes instead of double quotes

INVALID JSON: standard JSON requires double quotes around keys and strings. Single quotes are sometimes accepted by JavaScript-like formats, but not by JSON.

{
  'name': 'Rahul'
}

Single quotes fixed

VALID JSON: use double quotes.

{
  "name": "Rahul"
}

4. Missing quotes around property names

INVALID JSON: JavaScript object syntax and JSON are similar, but JSON requires quoted property names.

{
  name: "Rahul"
}

5. JSON is incomplete

INVALID JSON: the closing braces are missing. This often leads to an error such as unexpected end of JSON input.

{
  "name": "Rahul",
  "address": {
    "city": "Dehradun"
  }

Incomplete JSON fixed

VALID JSON: close both the nested object and the outer object.

{
  "name": "Rahul",
  "address": {
    "city": "Dehradun"
  }
}

6. Incorrect brackets

Objects use { } and arrays use [ ]. INVALID JSON: this starts an array but closes an object.

{
  "cities": ["Delhi", "Mumbai"}
}

Incorrect brackets fixed

VALID JSON: use the matching square bracket.

{
  "cities": ["Delhi", "Mumbai"]
}

7. Unescaped characters inside strings

INVALID JSON: the inner double quotes end the message string too early. Escape them with a backslash when they are part of the text.

{
  "message": "Rahul said "Hello""
}

Escaped quotes fixed

VALID JSON: the backslashes keep the inner quotes inside the string.

{
  "message": "Rahul said \"Hello\""
}

8. Your API returned HTML instead of JSON

Sometimes the JSON is not the problem. Your code expects a JSON response such as { "status": "success" }, but the server returns HTML. Trying to parse that HTML as JSON fails immediately. Check the actual response before assuming the JSON is malformed.

<!DOCTYPE html>
<html>
  <body>404 Not Found</body>
</html>
  • A 404 or 500 error page.
  • A login or access-denied page.
  • A proxy or CDN error page.
  • The wrong API endpoint.

9. Empty API response

Parsing an empty response as JSON can also fail, depending on the language or library. If code expected {} but received no response body, inspect the status and body before parsing. Do not assume every successful request has JSON content.

Expected valid JSON:
{}

Actual response body:
(empty)

10. Parsing an object that is already parsed

JAVASCRIPT, not JSON: JSON.parse() expects a JSON string. Passing a JavaScript object to it is a type mistake. Parse the string once, then use the resulting object directly.

const user = { name: "Rahul" };
JSON.parse(user); // incorrect

const json = '{"name":"Rahul"}';
const parsedUser = JSON.parse(json); // correct

How to fix a JSON parse error step by step

Start with the exact error message and its line or position information. Inspect the actual value, not just what you expected it to contain. If it is minified, format it. Validate it, correct quotes, commas, brackets, and escaping, then retry. When data is commonly malformed, repair it and validate the result again.

How to debug JSON.parse() errors in JavaScript

JAVASCRIPT, not JSON: try...catch lets the program handle a parsing failure instead of stopping without an explanation. Inspect the actual jsonString carefully; it may contain HTML, empty content, broken JSON, or unexpected characters. Avoid logging sensitive production data.

try {
  const data = JSON.parse(jsonString);
  console.log(data);
} catch (error) {
  console.error("Unable to parse JSON:", error);
}

JSON parse error vs JSON syntax error

A JSON syntax error describes a problem with the data's structure. A parse error is the failure that happens when a parser cannot interpret its input. They are closely related, but parsing can also fail when the input is HTML rather than JSON.

JSON parser vs JSON validator

A parser reads JSON and converts it into data a program can use. A validator checks whether text follows JSON syntax rules. Invalid JSON describes the data; a JSON parse error describes the failure when code tries to read it. JSONPlease Validator checks data locally in your browser before you pass it to an application.

Quick JSON parse error checklist

Use this before changing application code.

  • Is the response actually JSON, not HTML?
  • Is the response empty?
  • Are property names and strings in double quotes?
  • Are commas present where required, with no trailing comma?
  • Do all { } and [ ] brackets match?
  • Are quotes inside strings escaped?
  • Is there unexpected text before or after the JSON?
  • Are you trying to parse an object that is already parsed?

Real-world example: API JSON parse error

A developer requests /api/users/123 and expects VALID JSON: { "id": 123, "name": "Rahul" }. But an incorrect endpoint returns the HTML 404 page shown earlier. The correct approach is to check the HTTP status, inspect the response, confirm the endpoint, and parse as JSON only when the response is actually JSON.

{
  "id": 123,
  "name": "Rahul"
}

How to prevent JSON parse errors

Validate JSON you create by hand. Use a serializer when possible instead of constructing large JSON strings yourself. Check API response status and content before parsing, handle failures gracefully, use proper escaping, and test empty or unexpected responses. A formatter is useful when debugging minified JSON.

Frequently asked questions

What does JSON parse error mean? A parser could not turn the input into JSON data.

Why does JSON.parse() fail? The string may be invalid JSON, empty, HTML, or not a string at all.

How do I fix a JSON parsing error? Inspect the actual input, then validate and correct it.

Can an empty response cause a JSON parse error? Yes, depending on how it is parsed.

Why am I getting an unexpected token error? The parser found a character where JSON syntax did not allow one, often because it received HTML.

What does unexpected end of JSON input mean? The JSON ended before it was complete.

Can JSON use single quotes? No. Standard JSON uses double quotes.

How do I find the exact error? Use the reported line and position, then run the data through a JSON validator.

Related JSON tools