I am using NewtonSoft Json.NET library for parsing JSON files in a .NET app.
What I need to do is to pass the name of a node, and get the node if it exists, regardless of their level which is unknown beforehand.
For instance in a file:
string json = @"{
""Name"": ""Apple"",
""Expiry"": new Date(1230422400000),
""Price"": 3.99,
""ATest"": {
""MyTest"":
[
""blah"",
""blah""
]
}
}";
Is there a way to just use the value "MyTest" to fetch that node without having to know the parent’s name like jObject["ATest"]["MyTest"][0]?
AFAIK there’s no XPath-like query syntax for
JToken/JObject, but you can make one fairly easily – see code below.