On Sat, Jul 15, 2017 at 11:20 AM, Traun Leyden <traun.ley...@gmail.com> wrote: > > On go 1.7, I'm seeing a difference in behavior between json.Unmarshal and > json.Decoder when it comes to json numbers. > > This test program which compares json.Unmarshal() vs. json.NewDecoder() > behavior w.r.t to numbers works fine on go 1.8, but if I run it against go > 1.7 on OSX I get this error: > > $ go run main.go > 2017/07/15 11:19:15 json.Unmarshal() + json.Marshal(): { > "Doc": { > "GithubUsers": [ > { > "id": 3.411441e+06, > "type": "User" > } > ], > "_id": "github_users_default" > } > } > 2017/07/15 11:19:15 The id field was changed to floating point format > 2017/07/15 11:19:15 Couldn't unmarshal into github user object: json: cannot > unmarshal number 3.411441e+06 into Go value of type int > 2017/07/15 11:19:15 json.Decode() + json.Marshal(): { > "Doc": { > "GithubUsers": [ > { > "id": 3411441, > "type": "User" > } > ], > "_id": "github_users_default" > } > } > > > I'm going to update to Go 1.8 and forget about it, but out of curiosity does > anyone know if it was intentional change in Go 1.8?
Yes. Look for encoding/json under https://golang.org/doc/go1.8#minor_library_changes . "Marshal encodes floating-point numbers using the same format as in ES6, preferring decimal (not exponential) notation for a wider range of values. In particular, all floating-point integers up to 264 format the same as the equivalent int64 representation." Ian -- 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.