Closed natenho closed 2 years ago
Hello, I'm trying to apply a custom modifier to a field and the expected output should be the complete json, although it is ignoring the remaining fields.
package main import ( "fmt" "strings" "github.com/tidwall/gjson" ) func main() { gjson.AddModifier("case", func(json, arg string) string { if arg == "upper" { return strings.ToUpper(json) } if arg == "lower" { return strings.ToLower(json) } return json }) json := ` { "name": {"first": "Tom", "last": "Anderson"}, "age":37, "children": ["Sara","Alex","Jack"], "fav.movie": "Deer Hunter", "friends": [ {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]}, {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]}, {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]} ] } ` result := gjson.Get(json, `{"children":children|@case:upper,"name":name.first,"age":age}`) fmt.Println(result.Raw) }
{"children":["SARA","ALEX","JACK"], "name":"Tom", "age": 37}
{"children":["SARA","ALEX","JACK"]}
I just pushed a fix. Thanks for reporting.
@tidwall It's working now! Thank you for the amazingly fast response !!🥇
Hello, I'm trying to apply a custom modifier to a field and the expected output should be the complete json, although it is ignoring the remaining fields.
Reproduction
Expected Output (all fields)
Actual Output (missing all the other fields)