I am using C# Newtonsoft to represent data I have in JSON.
I am trying to selectively create a new JObject from an existing JObject by specifying which properties / sub properties I want.
Example code below:
var jobject = JObject.Parse(jsonText);
var list = new List<JToken>()
{
jobject["A"],
jobject["B"]["C"],
jobject["B"]["D"],
jobject["B"]["E"]["F"]
}
Combine(list);
JObject Combine(List<JToken> list)
{
/// What to put in here?
}
The expected output that I want, is Json that would be something like this, (Depending upon what the input jobject is)
{
"A" : <Data of jobject["A"]>,
"B" :
{
"C" : <Data of jobject["B"]["C"]>,
"D" : <Data of jobject["B"]["D"]>,
"E" :
{
"F" : <Data of jobject["B"]["E"]["F"]>
}
}
}
The source jobject may contain many other properties / fields. the final JToken created will be unique, but a given property used in a chain may not be (in this example, you can see jobject["B"] is used 3 times as first item)