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

add support for all basic golang number types #137

Open grische opened 4 months ago

grische commented 4 months ago

This fixes a bug where an int64 was detected for a number larger than the largest int64 number. The number 9993372000000000000 was detected as int64, despite the fact that it is outside of the limit 9223372036854775807 because 9993372030000000000 % 1 == 0, but well within float64 limits.

If the other data types are unwanted, let me know.

grische commented 4 months ago

@mholt I also think that other types but int might be actually harmful for many use cases. Imagine one is an ID and this ID is of int64 and just incremented. The example json might just contain the first few samples, i.e. turning into an int8 and then causing problems later on.

If you are OK with #141 I will hide this feature behind a flag (--small-ints maybe?) and leave the default to be int.

Note: the size of int is probably already int64, depending on the platform being used.

grische commented 4 months ago

I have prepared a commit for the new flag: a930048d431d32f085eb7d7574ca6ccba74eb17c

Once we have decided on how to proceed with #144 , I can update this PR.