The JSON value could not be converted 🟪 .NET

System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $.id

System.Text.Json couldn’t map a JSON value to the target .NET type — e.g. "42" (string) to int, null to a non-nullable type, or wrong enum value.

Seen on: .NET

Meaning

System.Text.Json is stricter than Newtonsoft: numbers in strings, case differences, enums as strings and comments are rejected unless configured.

Common causes

  • Number sent as a string
  • Enum sent as text without JsonStringEnumConverter
  • null into a non-nullable value type
  • Property type differs from the JSON shape (object vs array)

⚡ Quick fix

  1. Enable NumberHandling = AllowReadingFromString
  2. Add JsonStringEnumConverter
  3. Fix the DTO type or make it nullable

Detailed fix by platform

C#

  1. csharp
    builder.Services.ConfigureHttpJsonOptions(o => {
        o.SerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString;
        o.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
    });

How to diagnose

  1. Path — $.path in the message
  2. JSON — Actual value
  3. Options — Serializer settings

🔧 Still not fixed?

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

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