-Added support for root object in JSONPath filters
This commit is contained in:
@@ -949,5 +949,57 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
result = a.SelectTokens("$.[?(@.value)]").ToList();
|
||||
Assert.AreEqual(4, result.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RootInFilter()
|
||||
{
|
||||
string json = @"[
|
||||
{
|
||||
""store"" : {
|
||||
""book"" : [
|
||||
{
|
||||
""category"" : ""reference"",
|
||||
""author"" : ""Nigel Rees"",
|
||||
""title"" : ""Sayings of the Century"",
|
||||
""price"" : 8.95
|
||||
},
|
||||
{
|
||||
""category"" : ""fiction"",
|
||||
""author"" : ""Evelyn Waugh"",
|
||||
""title"" : ""Sword of Honour"",
|
||||
""price"" : 12.99
|
||||
},
|
||||
{
|
||||
""category"" : ""fiction"",
|
||||
""author"" : ""Herman Melville"",
|
||||
""title"" : ""Moby Dick"",
|
||||
""isbn"" : ""0-553-21311-3"",
|
||||
""price"" : 8.99
|
||||
},
|
||||
{
|
||||
""category"" : ""fiction"",
|
||||
""author"" : ""J. R. R. Tolkien"",
|
||||
""title"" : ""The Lord of the Rings"",
|
||||
""isbn"" : ""0-395-19395-8"",
|
||||
""price"" : 22.99
|
||||
}
|
||||
],
|
||||
""bicycle"" : {
|
||||
""color"" : ""red"",
|
||||
""price"" : 19.95
|
||||
}
|
||||
},
|
||||
""expensive"" : 10
|
||||
}
|
||||
]";
|
||||
|
||||
JArray a = JArray.Parse(json);
|
||||
|
||||
List<JToken> result = a.SelectTokens("$.[?($.store.bicycle.price < 20)]").ToList();
|
||||
Assert.AreEqual(1, result.Count);
|
||||
|
||||
result = a.SelectTokens("$.[?($.store.bicycle.price < 10)]").ToList();
|
||||
Assert.AreEqual(0, result.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user