Checking the result of JsonConvert.DeserializeObject (think "try to parse") using JSON.Net

I have incoming messages that I need to try and analyze in my own object structure. SOme of them are well-formed JSON obejcts, and some are just nonsense.

I am using JsonConvert.DeserializeObject<MyObject>(incmoingString); for this. This, however, sometimes gives me an exception when incoming full garbage. In other cases, I get an incomplete object structure when the incoming line looks OK - and finally it sometimes works.

I wrapped the conversion in try / catch and, than manually, confirmed that I have the properties necessary for a deserialized result.

Is there a better way to do this?

+7
source share
1 answer

Json.NET supports JSON Schema . You can create a schema with all the necessary properties marked and checking the incoming JSON for it before deserializing.

+4
source share

All Articles