super json
JSON picker and converter.
API
Pick
buf := []byte(`{
"name": "tree.xie",
"address": "GZ",
"no": 123
}`)
data := superjson.Pick(buf, []string{
"name",
"no",
})
// {"name":"tree.xie","no":123}
fmt.Println(string(data))
Omit
buf := []byte(`{
"name": "tree.xie",
"address": "GZ",
"no": 123
}`)
data := superjson.Omit(buf, []string{
"address",
})
// {"name":"tree.xie","no":123}
fmt.Println(string(data))
Filter
buf := []byte(`{
"name": "tree.xie",
"address": "GZ",
"no": 123
}`)
data := superjson.Filter(buf, func(key, _ string) (omit bool, newKey string) {
// omit the no
if key == "no" {
return true, ""
}
// convert the address to addr
if key == "address" {
return false, "addr"
}
// key original
return false, key
})
// {"name":"tree.xie","addr":"GZ"}
fmt.Println(string(data))
Mask
buf := []byte(`{
"name": "tree.xie",
"address": "GZ",
"no": 123
}`)
data := superjson.Mask(buf, func(key, _ string) (newValue string) {
// mask the no
if key == "no" {
return `"***"`
}
return ""
})
// {"name":"tree.xie","address":"GZ","no":"***"}
fmt.Println(string(data))
CamelCase
buf := []byte(`{
"book_author_name": "tree.xie",
"book_no": 123
}`)
data := superjson.CamelCase(buf)
// {"bookAuthorName":"tree.xie","bookNo":123}
fmt.Println(string(data)
SnakeCase
buf := []byte(`{
"bookAuthorName": "tree.xie",
"bookNo": 123
}`)
data := superjson.SnakeCase(buf)
// {"book_author_name":"tree.xie","book_no":123}
fmt.Println(string(data))