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
Executing JToken.SelectTokens("$.*") on a valid JSON array should produce multiple JToken results
Actual Behavior
Newtonsoft.Json.JsonException: Property '*' not valid on JArray.
at Newtonsoft.Json.Linq.JsonPath.FieldFilter.ExecuteFilter(JToken root, IEnumerable`1 current, JsonSelectSettings settings)+MoveNext()
at System.Collections.Generic.LargeArrayBuilder…
To add to the report, according to the JsonPath draft spec, section 1.4.4, .* is a shorthand/alias for [*]. Therefore, $.* is equivalent to $[*].
However, not only does Newtonsoft.Json implement .* incorrectly, it also implements [*] incorrectly.
Since .* is a shorthand/alias for [*], both .* and [*] should be applicable to objects AND arrays equally. But Newtonsoft.Json treats both .* and [*] differently, in violation of the JsonPath draft spec i linked to above. .* works on objects but incorrectly not on arrays, as the report pointed out. And [*] works on arrays but incorrectly not on objects.
P.S.: While the very first Json draft spec version 00 -- draft-ietf-jsonpath-base-00 -- also already explains the .* semantics in section 3.6.1, the draft spec version 00 seems to lack any formal definition for [*] -- it only mentions
JSONPath allows the wildcard symbol "*" for member names and array indices
in passing. The same mention appears at https://goessner.net/articles/JsonPath/, and Newtonsoft.Json therefore seems to also violate the old Goessner draft from 2007 in this respect...
Source/destination JSON
Expected behavior
Executing
JToken.SelectTokens("$.*")
on a valid JSON array should produce multiple JToken resultsActual Behavior
Repro Steps
https://dotnetfiddle.net/ginhZu
Running the same query here https://json-everything.net/json-path produces a valid result.
WorkAround
JsonPath
$[*]
products the expected resultThe text was updated successfully, but these errors were encountered: