go-json
go-json copied to clipboard
Support multiple conversion types
Hi, Now with introduction of generics Maybe it will be worthy to support multiple json values parsers for same key
i.e If we have field of bool It will accept both: true “true”
same for numbers If i take example from Java Json parsers can parse both types(base type, and conversion from string)
Could you give me a concrete example of the code you would like to use ?
@goccy hi, yes sure
in general, pretty much what json.Number provides, just automatically do it for several types
lets say we have struct:
type CommonProviderResponse struct { Code int json:"code" }
and request of:
{"code":200}
struct will be filled with 200
and if request of:
{"code":"200"}
also struct will be filled with 200
same goes for boolean type, automatically fill it with the type of the struct pretty much, each of the types should accept string, and parse it to the expected value in struct if it is possible