Closed Cluas closed 2 years ago
// You can edit this code! // Click here and start typing. package main import ( "fmt" "github.com/tidwall/gjson" ) func main() { gjson.AddModifier("exist", func(json, _ string) string { fmt.Println("moExist executed!") r := gjson.Parse(json) if !r.Exists() { return "false" } if r.IsObject() && len(r.Map()) == 0 { return "false" } if r.IsArray() && len(r.Array()) == 0 { return "false" } return "true" }) r := gjson.Parse(`{"stock_score":null}`) fmt.Println(r.Get("stock_score.multi_letter.@exist").String()) }
https://go.dev/play/p/BcIxxd20JUX
Expected to be executed here, but not actually executed.
https://go.dev/play/p/BcIxxd20JUX
Expected to be executed here, but not actually executed.