We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import ("github.com/golang-module/carbon/v2") type Person struct { Field1 string `json:"field1,omitempty"` Field2 carbon.Carbon `json:"field2,omitempty" carbon:"omitempty"` } var p Person err := json.Unmarshal([]byte("{\"field1\":null,\"field2\":null}"), &p) fmt.Println(err, p)
cannot parse string "null" as carbon by layout "2006-01-02 15:04:05", please make sure the value and layout match { }
Add the omitempty tag to prevent parsing errors ?
The text was updated successfully, but these errors were encountered:
{"field1":null,"field2":null} -> {"field1":"","field2":""}
{"field1":null,"field2":null}
{"field1":"","field2":""}
Sorry, something went wrong.
The responses of some APIs are null, and I have no control over them.
Support decoding json strings containing null #225
7e235e0
59b34ad
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
No branches or pull requests
Add the omitempty tag to prevent parsing errors ?
The text was updated successfully, but these errors were encountered: