You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using SelectToken with JSONPath, I want to search for “a” recursively, then get the “name” non-recursively. I expect to find a single token: the “name” node, which is an immediate child of “a”.
Actual behavior
When I use the dot-notation — “$..a.name” — it returns correctly the “name” token, which is a child of “a”.
However, when I use the alternative bracket-notation — “$..['a']['name']” — it returns both of the “name” tokens. The second “name” should not be returned, because it is not an immediate child of “a”.
Steps to reproduce
// In C Sharp, in a console application,// using Newtonsoft.Json 12.0.2 and .NET Framework 4.8.stringjson=@" { ""root"": { ""a"": { ""name"": ""John"", ""b"": { ""name"": ""Sarah"" } } } } ";JTokent=JToken.Parse(json);intcount1=t.SelectTokens("$..a.name").Count();// result: 1, expected: 1intcount2=t.SelectTokens("$..['a']['name']").Count();// result: 2, expected: 1
The text was updated successfully, but these errors were encountered:
Source JSON
Expected behavior
Using SelectToken with JSONPath, I want to search for “a” recursively, then get the “name” non-recursively. I expect to find a single token: the “name” node, which is an immediate child of “a”.
Actual behavior
When I use the dot-notation — “$..a.name” — it returns correctly the “name” token, which is a child of “a”.
However, when I use the alternative bracket-notation — “$..['a']['name']” — it returns both of the “name” tokens. The second “name” should not be returned, because it is not an immediate child of “a”.
Steps to reproduce
The text was updated successfully, but these errors were encountered: