I have a struct like this:
type MyStruct struct {
Name string `json:"name"`
Age int `json:"age"`
Email string `json:"email"`
}
然后我有一些值(可以是默认值,这意味着我不需要更新这个值)作为HTTP请求数据输入.我注意到生成的JSON正文将始终包含所有三个字段(name
、age
和email
),即使我不需要更新所有字段.这样地:
{
"name":"Kevin",
"age":10,
"email":""
}
Is there a way to Marshal so that the JSON body contains not all fields with the same struct? Example:
{
"name":"kevin"
}