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
- Enable NumberHandling = AllowReadingFromString
- Add JsonStringEnumConverter
- Fix the DTO type or make it nullable
Detailed fix by platform
C#
- csharp
builder.Services.ConfigureHttpJsonOptions(o => { o.SerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString; o.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); });
How to diagnose
- Path — $.path in the message
- JSON — Actual value
- 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:
Similar errors
Most viewed in .NET
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026