go
go copied to clipboard
Auto lowercase support
Could json-iterator support auto lowercase json field?
code example:
type User struct {
ID int `json:"-"`
Name string
Age int
Email string
QQNumber string `json:"QQ"`
}
user := User{
ID: 1,
Name: "MJ",
Age: 51,
Email: "[email protected]",
QQNumber: "20090625",
}
b, _ := jsoniter.Marshal(user)
fmt.Println(string(b))
// we need a function like `MarshalSmart`, it can auto lowercase the first letter of json fileds if the struct field has no json tag defined.
b, _ := jsoniter.MarshalSmart(user)
fmt.Println(string(b))
prefer output:
// output of jsoniter.Marshal
{
"Name": "MJ",
"Age": 51,
"Email": "[email protected]",
"QQ": "20090625"
}
// output of jsoniter.MarshalSmart
{
"name": "MJ",
"age": 51,
"email": "[email protected]",
"QQ": "20090625"
}
the same as jsoniter.UnMarshalSmart
It is supported by the extension. see extra.naming_strategy.go