entity.parse.failed 🔌 API

API Error: Malformed JSON in request body (entity.parse.failed / JSON parse error)

The server couldn’t parse the request body as JSON, so it rejected the request before looking at any field.

Seen on: REST API

Meaning

This is the server-side twin of the browser’s “Unexpected token in JSON” error: the bytes your client sent are not valid JSON. Express/body-parser reports it as type entity.parse.failed, Spring as “JSON parse error”, Django REST Framework as “JSON parse error - Expecting value”, and many APIs simply say “Malformed JSON” or “Problems parsing JSON”.

Typical culprits are hand-built JSON strings, single quotes, trailing commas, an object passed without JSON.stringify (sent as “[object Object]”), or a body sent as form data while the header says application/json.

Common causes

  • Body built by string concatenation (unescaped quotes, newlines)
  • Single quotes or trailing commas (valid in JS, invalid in JSON)
  • Object sent without JSON.stringify → "[object Object]"
  • Content-Type: application/json but the body is form-encoded or empty
  • Shell quoting in curl mangled the JSON

⚡ Quick fix

  1. Always build bodies with JSON.stringify / json.dumps, never by hand
  2. Validate the payload with a JSON linter
  3. Make the body and Content-Type match

Detailed fix by platform

Node.js

  1. await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });

curl

  1. bash
    # put the JSON in a file to avoid shell quoting problems
    curl -X POST https://api.example.com/v1/items -H 'Content-Type: application/json' --data @body.json

Express

  1. bash
    app.use(express.json());
    app.use((err, req, res, next) => {
      if (err.type === 'entity.parse.failed') return res.status(400).json({ error: 'Malformed JSON' });
      next(err);
    });

How to diagnose

  1. Raw body — Paste the exact bytes sent into a JSON validator
  2. Header — Content-Type matches the body format?
  3. Client — Was the object stringified?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.