Yelnats
How can I convert null entries in JSON data to a default value?
I have JSON data that contains null entries for some values. It would make the business code a lot easier if all the data that comes out of deserialization is uniform. For example, the property "strength" could be null, but I would like it to be deserialized to 0. It would also be ideal if I could do something similar so that I construct null members by default, for example a "friend = null" property would instead do "new Friend()". I looked into
JsonSerializerOptions.DefaultIgnoreCondition
but that seems to only affect serialization, and not deserialization. I could transform all the data from a deserialized to a business ready form, but that seems like extra work if I can just get deserialization right and not have to double the class count.21 replies