'JSON.NET only return nodes that contain a specific child node
When doing a SelectToken in JSON.NET, is there a way I could return a list of JTokens of elements that contain a certain child element? For example, is there a SelectToken that would only return the nodes where the "status" child exists from my sample JSON below?
"Fruits": [
{
"id": "1",
"value": "apple"
},
{
"id": "2",
"value": "banana",
"status": [
{
"fresh": "yes",
"peeled": "no"
}
]
},
{
"id": "3",
"value": "orange",
"status": [
{
"fresh": "yes",
"peeled": "yes"
}
]
}
]
Solution 1:[1]
the simpliest way is
var fruitsWithStatus=JObject.Parse(json)["Fruits"].Where(f => f["status"]!=null ).ToList();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Serge |
