AFAIK (and someone will probably provide something better) you need to do 
something like this: 

https://play.golang.org/p/riq-m6cgZu

> On Jun 17, 2016, at 2:37 PM, jg...@bitgirder.com wrote:
> 
> We have an upstream provider of JSON data which sends integer data
> types as floating point literals with a "0" decimal part. By default
> json.Decoder doesn't allow this and fails:
> 
>    https://play.golang.org/p/MEJlg1n3vs
> 
> Unfortunately this provider is almost certain not to change this, and
> so we just have to deal with it as clients of their API. What are some
> ways we could handle this?
> 
> Things that come to mind:
> 
>    - Submit a change to encoding/json that allows us to set some sort
>      of number processing function to customize its behavior (or to
>      set some sort of policy which allows number literals ending in
>      \.0*$ for integer targets)
> 
>    - Create a custom io.Reader which wraps in input stream by reading
>      individual tokens from it using an internal json.Decoder, and
>      then emits number literals without trailing ".0". 
> 
>    - Buffer all inbound decodes into a map[string]interface{} and set
>      the decoder to UseNumber(), and then replace those json.Numbers
>      with corrected ones, then serialize back and decode once more
>      into the destination (this is similar to the token-stream
>      approach above)
> 
> Are there other approaches I'm overlooking?
> 
> jonathan
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to