[Golang] Multiple Type In Struct
Read OriginalThis article provides a Golang tutorial on handling JSON fields that can be either a string or a number when unmarshalling into a struct. It demonstrates using the json.Number type from the encoding/json package to avoid type mismatch errors. The article includes a code example showing how to unmarshal JSON with amount as both a string and a number, and how to convert the json.Number to float64, int64, or string. This is useful for developers dealing with flexible JSON APIs in Go.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser
Top of the Week
No top articles yet