Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle modifiers with options #291

Merged
merged 1 commit into from Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion gjson.go
Expand Up @@ -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
}
}
Expand Down
19 changes: 19 additions & 0 deletions gjson_test.go
Expand Up @@ -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 >>>")
}
}