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

Features and Ideas #21

Open dcarbone opened 7 years ago

dcarbone commented 7 years ago

Hey there,

First I want to thank you for creating this generator, was a big help.

Secondly, I have created my own implementation of this in php here: dcarbone/json-to-go

I added a few features I needed for various projects, namely:

My use cases for the above generally revolve around mapping request and response types for large api's (hundreds of separate endpoints, which can lead to over a thousand separate models), and wanting to generate them on the fly.

I am not sure how many of these features would be helpful to the world at large, but I wanted to see if any would be of interest to you, and possibly provide ideas for future development.

If one stands out, let me know and I can work on a PR for your JS version.

Thanks again! - Daniel

mholt commented 7 years ago

Hey @dcarbone - thanks for your feedback! Glad you liked it enough to fork and build on it. I did read your post but I need to go through it again in more detail when I have a chance; I do have a few questions on some of those points. Other projects are consuming my time right now, so it might be a while.

grische commented 4 months ago

Force int -> float Because js ints are a lie

If we convert int, in particular int64, to float we will loose precision. This should also cause problems in golang when trying to unmarshall jsons with these kind of numbers. I think the current detection as well as the new detection of #137 is better.

dcarbone commented 4 months ago

The purpose of that conversion is due to the fact that sample input may only contain int-like values, when in fact the value could just be a float with zero precision when serialized.

Precision loss is irrelevant if it fails to unmarshal in the first place :)