Fix Cannot Deserialize JSON Errors
A deserialization error means valid or invalid JSON could not be converted into the target model. Find the exact JSON path and compare its runtime value with the expected type.
Separate parsing from mapping
First validate the raw response or request body. Missing commas, unescaped characters, and truncated data are syntax errors. If the document parses successfully, the failure is usually a mapping problem involving type, shape, naming, nullability, or serializer settings. Preserve a redacted failing sample and the complete error, including path, line, column, and target type when available.
Locate the first incompatible value
Follow the reported path through nested objects and arrays. Compare the actual JSON token with the model: string, number, boolean, null, object, or array. Frequent mismatches include a quoted number for an integer, one object instead of a list, an envelope such as {"data":[]} instead of the array itself, and a boolean represented as 0 or "false".
Check nullability and missing fields
A missing property and an explicit null may have different meanings. Required non-null fields should reject both when the contract demands a value. Optional fields need a deliberate default or nullable type. Avoid changing every field to a string or nullable value just to accept one bad payload; that moves the inconsistency deeper into the application.
Review names, enums, and dates
Verify case conversion and configured property aliases, especially snake_case versus camelCase. Check whether unknown fields are ignored or rejected. Enum text may differ in case or contain a newly added value. Date parsers can reject an unexpected timezone, fractional precision, locale format, or seconds-versus-milliseconds timestamp. Document one representation in the schema.
Inspect generated and generic types
Generated models can become stale when the API changes. Regenerate them from the current contract and review the diff. In languages with erased or runtime generic information, make sure the serializer receives the complete collection and nested type. Confirm custom converters are registered for the intended property and do not silently affect unrelated values.
Reduce the payload and enforce the contract
Remove unrelated properties until the smallest sample still fails. Add fields back after correcting the target model or producer. Validate payloads at boundaries with a JSON Schema or OpenAPI operation so the error names the contract violation before business logic runs. Use the JSON Validator for syntax and the JSON Schema Validator for shape.
Frequently Asked Questions
Can valid JSON fail deserialization?
Yes. Its runtime shape can still disagree with the model.
Why do object and array mismatches occur?
The model and payload disagree about collection or envelope shape.
Should unknown fields be ignored?
Choose deliberately based on the API compatibility policy.