Merge pull request #291 from janisz/master

Handle modifiers with options
This commit is contained in:
Josh Baker 2022-08-16 06:44:06 -07:00 committed by GitHub
commit 8bf80a300b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -945,7 +945,7 @@ func isDotPiperChar(s string) bool {
// check that the next component is *not* a modifier. // check that the next component is *not* a modifier.
i := 1 i := 1
for ; i < len(s); i++ { for ; i < len(s); i++ {
if s[i] == '.' || s[i] == '|' { if s[i] == '.' || s[i] == '|' || s[i] == ':' {
break break
} }
} }

View File

@ -2554,3 +2554,22 @@ func TestIndexAtSymbol(t *testing.T) {
}` }`
assert(t, Get(json, "@context.@vocab").Index == 85) assert(t, Get(json, "@context.@vocab").Index == 85)
} }
func TestDeepModifierWithOptions(t *testing.T) {
rawJson := `{"x":[{"y":[{"z":{"b":1, "c": 2, "a": 3}}]}]}`
jsonPathExpr := `x.#.y.#.z.@pretty:{"sortKeys":true}`
results := GetManyBytes([]byte(rawJson), jsonPathExpr)
assert(t, len(results) == 1)
actual := results[0].Raw
expected := `[[{
"a": 3,
"b": 1,
"c": 2
}
]]`
if expected != actual {
t.Fatal(strconv.Quote(rawJson) + "\n\t" +
expected + "\n\t" +
actual + "\n\t<<< MISMATCH >>>")
}
}