Working on a project using .NET 7.0 and System.Text.Json to deserialize JSON to basic POCO classes and running into the following error:
The JSON value could not be converted to Models.ESPN.Clock. Path: $.status.clock | LineNumber: 0 | BytePositionInLine: 6823.
Below is the JSON related to the error:
{
"status":{
"clock":{
"value":"0.0n",
"type":"Big Number"
},
"displayClock":"0:00",
"period":4
}
}
And the related POCO classes:
public class Status
{
public Clock clock { get; set; }
public string displayClock { get; set; }
public double period { get; set; }
}
public class Clock
{
public string value { get; set; }
public string type { get; set; }
}
Note: JSON and classes are snippets from larger data set. Minimized to data set related to error.
From debugging the JSON deserialization seems to be throwing exemption trying to map the JSON $.status.clock.value of "0.0n". I have tried setting the type as string, int, and BigInteger and all results in same error.
How do I handle a JSON value of "0.0n" in my class?
Dot Net Fiddle reproducible code: https://dotnetfiddle.net/7q5xtq
Credit @IanKemp for pointing me in the right direction. Turned out a browser plug-in was not parsing the JSON response correctly in which I was creating my POCO classes. Lesson learned to not use browser plug-ins! See post comments for more details.