Closed a8ss closed 8 months ago
{"field1":null,"field2":null}
-> {"field1":"","field2":""}
The responses of some APIs are null, and I have no control over them.
Supported since v2.3.10
type Person struct {
Birthday1 carbon.Carbon
Birthday2 carbon.Carbon
}
str := `{
"birthday1":"",
"birthday2":null
}`
var person Person
unmarshalErr := json.Unmarshal([]byte(str), &person)
fmt.Println(unmarshalErr) // nil
fmt.Println(person.Birthday1.String()) // empty string
fmt.Println(person.Birthday2.String()) // empty string
Add the omitempty tag to prevent parsing errors ?