go-json icon indicating copy to clipboard operation
go-json copied to clipboard

Support multiple conversion types

Open itzikiusa opened this issue 3 years ago • 2 comments

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)

itzikiusa avatar Mar 22 '22 17:03 itzikiusa

Could you give me a concrete example of the code you would like to use ?

goccy avatar Mar 25 '22 15:03 goccy

@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

itzikiusa avatar Mar 30 '22 05:03 itzikiusa