assign value based on JSON value using JsonSerializer

So lately ive been getting into the JsonSerializer to create my objects based on a given JSON string, but now im facing the following issue: I have a checklist object in my project that gets populaed by the JSON gotten from a REST API. the issue however is that the checkbox value is not returned as boolean but rather string: "complete" or "incomplete", is there a way to directly convert this to bool? TLDR; How to check and assign custom value using JsonSerializer
4 Replies
tera
tera9mo ago
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
tera
tera9mo ago
you could use this or just use an enum instead
Jimmacle
Jimmacle9mo ago
is there a practical reason it needs to be stored as a string instead of a boolean IsComplete?
The Fog from Human Resources
there is none, but its the API im working with so sadly i cant change it :SCcrying:
Want results from more Discord servers?
Add your server