I have a set of, well, interestingly formed JSON that I need to read using C#, in my case specifically using JSON.NET although that could likely be done using System.Text.Json as well.
The data has a structure similar to this:
[
{
"Name": "Name A",
"Value": "Apples"
},
{
"Name": "Name B",
"Value": {
"key1": "value1",
"key2": "value2"
}
}
]
In short, an array of objects of somewhat different shape, specifically the 'Value' property is varying. I am ONLY interested in records having Value data of key/value (Dictionary<string, string>) type, if that helps.
What is the best (simplest in this case) way to read this data into some kind of typed representation? I say typed as that is what I would like to work with but it is not strictly a requirement.
Something like "Hey JSON.NET, please give me all records where 'Value' is of type key/value, if possible as an object structure where Value is materialized as typed Dictionary<string, string> objects. Other records may be discarded if that helps. Thanks!".
It would be really great if this could somehow be implemented using POCO objects.
JArray(where each value will be aJObject) and then transform from that into the name/dictionary pairs you want.