Open gorillapower opened 9 months ago
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 result