mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.51k stars 475 forks source link

Fix time parsing for precision, and float -> issue. #9

Closed relistan closed 9 years ago

relistan commented 9 years ago

Because Javascript can't tell the difference between 1.0 and 1 you end up with Go structs that are using int where float is required. This PR hacks around this by doing a global substitution on the incoming buffer to replace .0 with .1. This will probably almost always do the right thing. There could be places where the key name is meant to be a string and has a .0 in it. That seems reasonably pathological to me so I believe this solution is good enough.

Secondly, precision times with mill/nano-seconds were not parsing into time.Time types and this fixes that.

Thanks for the great tool!

mholt commented 9 years ago

Thanks!