Update the documentation of custom modifiers to specify the need of quotes in return type
Author: sharadregotiCreated Dec 23, 2022Updated Sep 8, 2026
Can we update the documentation of custom modifiers, to clearly specify that return type string should have quotes. If it doesn't have quotes we get empty value as result
package main
import (
"strings"
"github.com/tidwall/gjson"
)
const json = `{"name":{"first":"Janet","last":"Prichard"},"age":47}`
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
})
gjson.AddModifier("age", func(json, arg string) string {
if arg == "0" {
// Quotes is necessary here
return `"test"`
}
return json
})
value2 := gjson.Get(json, "name.last|@case:upper")
println(value2.String())
value := gjson.Get(json, "name.last|@age:0")
println(value.String())
}
I am thinking of adding this as note below custom modifier doc section
Please note that returned string type should have double quotes in it.
gjson.AddModifier("age", func(json, arg string) string {
if arg == "custom-arg" {
// Quotes is necessary here
return `"test"`
}
return json
})Source: tidwall/gjson