I have a JSON string that contains an object that is complex, nested, and will likely change schema in the future. I would like to hand it off to a web API to serialize in the content negotiation pipeline as needed.
Is there any straightforward way of doing this? I've read other answers on SO, but they only discuss either cases where you know the schema you want beforehand (eg deserialize with JsonConvert.DeserializeAnonymousType
) or when you know the nesting depth that you want to deserialize to.
So for example let's say I have the following string:
@"{
name: "Dan"
children: [
{
name: 'Fred',
},
{
name: 'Fannie',
age: 30,
children: {
own: [
{name: "Barney"},
{name: "Angela"}
],
adopted: {
{name: "Sven"}
}
}
}
}"
I don't know what the schema of it is, and it can change at any time, I just want to be able to send it via web api with proper content negotiation.
I can do JObject.Parse(...)
but web api can't handle JObject
s properly. It would handle dictionaries properly, but I can't seem to figure out how to use JSON.Net to deserialize dictionaries of arbitrary nesting depth.