C# 10 - how to to Deserialize Complex Nested JSON with System.Text.Json
I'm experimenting with Hey everyone, I'm running into an issue that's driving me crazy. I'm running into issues deserializing a complex nested JSON structure using System.Text.Json in my C# 10 application. The JSON I'm trying to deserialize looks like this: ```json { "user": { "id": 1, "name": "John Doe", "address": { "street": "123 Main St", "city": "Anytown" } } } ``` I have the following classes defined for this structure: ```csharp public class User { public int Id { get; set; } public string Name { get; set; } public Address Address { get; set; } } public class Address { public string Street { get; set; } public string City { get; set; } } ``` When I attempt to deserialize it using the following code: ```csharp string jsonString = /* JSON string */; User user = JsonSerializer.Deserialize<User>(jsonString); ``` I receive the behavior: ``` System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $.user.id | Line number: 1 | Byte position: 20. ``` It seems like the deserializer is not able to locate the properties correctly due to the nested structure of the JSON. I tried creating a root class like this: ```csharp public class Root { public User User { get; set; } } ``` Then I modified the deserialization code: ```csharp Root root = JsonSerializer.Deserialize<Root>(jsonString); User user = root.User; ``` But I still encounter the same behavior. I've verified that the JSON structure matches my classes. Is there a specific configuration or attribute I need to apply to handle nested JSON deserialization properly in C# 10? Any guidance would be greatly appreciated! How would you solve this? Any examples would be super helpful.