From 9e848707d6d313c64b3815dd0de8c45b9e9d4dbc Mon Sep 17 00:00:00 2001 From: Tomasz Janiszewski Date: Tue, 9 Aug 2022 15:39:36 +0200 Subject: [PATCH] Handle modifiers with options --- gjson.go | 2 +- gjson_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gjson.go b/gjson.go index 9b0db4e..330218d 100644 --- a/gjson.go +++ b/gjson.go @@ -945,7 +945,7 @@ func isDotPiperChar(s string) bool { // check that the next component is *not* a modifier. i := 1 for ; i < len(s); i++ { - if s[i] == '.' || s[i] == '|' { + if s[i] == '.' || s[i] == '|' || s[i] == ':' { break } } diff --git a/gjson_test.go b/gjson_test.go index 8ddab94..c91a2d8 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -2554,3 +2554,22 @@ func TestIndexAtSymbol(t *testing.T) { }` 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 >>>") + } +}