The web service I'm calling returns a JSON response with much more data than I actually need to use and it's causing the deserialization process to take a very long time.
I'm using VB.NET and the Newtonsoft JSON library.
Using the following JSON as an example, how can I remove all values except the 'id' value?
{"results": [
{"id":"1234", "name":"name value", "logo":"<some base64 encoded string>"},
{"id":"1234", "name":"name value", "logo":"<some base64 encoded string>"},
{"id":"1234", "name":"name value", "logo":"<some base64 encoded string>"},
{"id":"1234", "name":"name value", "logo":"<some base64 encoded string>"},
{"id":"1234", "name":"name value", "logo":"<some base64 encoded string>"}
]}
Would regular expressions be the best way?
I have just learnt that it also needs to handle a nested array of objects that also have an id
property. The nested id
property should be excluded from the final JSON.
{"results": [
{"id":"1234", "name":"name value", "categories":[{"id":"1","name":"category"}]},
{"id":"1234", "name":"name value", "categories":[{"id":"1","name":"category"}]},
{"id":"1234", "name":"name value", "categories":[{"id":"1","name":"category"}]},
{"id":"1234", "name":"name value", "categories":[{"id":"1","name":"category"}]},
{"id":"1234", "name":"name value", "categories":[{"id":"1","name":"category"}]}
]}