not JSON serializable Python Origin: Application & API Last updated 14 Oct 2026

TypeError: Object of type datetime is not JSON serializable

json.dumps() met a type it doesn’t know how to encode (datetime, Decimal, set, custom objects).

Exact message you may see is not JSON serializableObject of type
Seen on: Python

Meaning

The json module only handles dict, list, str, int, float, bool and None. Convert other types or pass a default= function.

Common causes

  • datetime/date objects
  • Decimal from databases
  • set instead of list
  • ORM model instances

⚡ Quick fix

  1. json.dumps(data, default=str) for quick conversions
  2. Convert explicitly (isoformat(), float(), list())
  3. Use the framework’s serializer (DRF, pydantic model_dump_json)

Detailed fix by platform

Python

  1. json.dumps(payload, default=lambda o: o.isoformat() if hasattr(o, "isoformat") else str(o))

How to diagnose

  1. Type — Which type is named?
  2. Field — Where in the data?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

circular JSON — TypeError: Converting circular structure to JSON (JavaScript)circular JSONentity.parse.failed — API Error: Malformed JSON in request body (entity.parse.failed / JSON parse error) (API)entity.parse.failedHttpMessageNotReadableException — HttpMessageNotReadableException: JSON parse error / Required request body is missing (Java)HttpMessageNotReadabl…InvalidDefinitionException — com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class X and no properties discovered (Java)InvalidDefinitionExce…is an invalid start of a value — System.Text.Json: '<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0 (.NET)is an invalid start o…JSONDecodeError — json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) (Python)JSONDecodeErrorJsonException object cycle — JsonException: A possible object cycle was detected (.NET)JsonException object …MismatchedInputException — com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList` from Object value (Java)MismatchedInputExcept…not JSON …

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.