Skip to content

Commit 9e84870

Browse files
committed
Handle modifiers with options
1 parent 475b403 commit 9e84870

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

gjson.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ func isDotPiperChar(s string) bool {
945945
// check that the next component is *not* a modifier.
946946
i := 1
947947
for ; i < len(s); i++ {
948-
if s[i] == '.' || s[i] == '|' {
948+
if s[i] == '.' || s[i] == '|' || s[i] == ':' {
949949
break
950950
}
951951
}

gjson_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,3 +2554,22 @@ func TestIndexAtSymbol(t *testing.T) {
25542554
}`
25552555
assert(t, Get(json, "@context.@vocab").Index == 85)
25562556
}
2557+
2558+
func TestDeepModifierWithOptions(t *testing.T) {
2559+
rawJson := `{"x":[{"y":[{"z":{"b":1, "c": 2, "a": 3}}]}]}`
2560+
jsonPathExpr := `x.#.y.#.z.@pretty:{"sortKeys":true}`
2561+
results := GetManyBytes([]byte(rawJson), jsonPathExpr)
2562+
assert(t, len(results) == 1)
2563+
actual := results[0].Raw
2564+
expected := `[[{
2565+
"a": 3,
2566+
"b": 1,
2567+
"c": 2
2568+
}
2569+
]]`
2570+
if expected != actual {
2571+
t.Fatal(strconv.Quote(rawJson) + "\n\t" +
2572+
expected + "\n\t" +
2573+
actual + "\n\t<<< MISMATCH >>>")
2574+
}
2575+
}

0 commit comments

Comments
 (0)