On Thu, 2 Mar 2017 03:35:39 -0800 (PST)
Basile Starynkevitch <bas...@starynkevitch.net> wrote:

[...]
> > JSON itself doesn't distinguish between integers and floats so it
> > could be a bad fit for your use case. 
[...]
> In theory you are right, json.org don't make the difference. In
> practice, a lot of JSON libraries (e.g. jansson 
> <https://jansson.readthedocs.io/en/2.9/apiref.html#number> for C,
> jsoncpp
> <http://open-source-parsers.github.io/jsoncpp-docs/doxygen/class_json_1_1_value.html>
> for C++,  YoJson <https://github.com/mjambon/yojson> for Ocaml)  are
> distinguishing them, in particular because they are different types
> at the hardware level.

I think you're focusing on an irrelevant side of this equation: when
a JSON library does unmarshaling, it either "knows" the schema of the
data it unmarshals -- either explicitly or, say, through reflection
over the type of the receiving variable or through some other means, --
and in this case the library interprets the JSON value it reads in a
way to fullfill the receiver's data type, or the schema is not known --
say, we're dealing with unmarshaling into a generic container type like
map[string]interface{} or with a typeless language, and then the data
type of the resulting value is usually inferred from the data type of
the source JSON value.

Both cases happen in the wild, but to state that only the latter case
is "the correct" approach to parsing JSON is IMO incorrect.

Say, when you would use encoding/json to unmarshal that literal 1 into
a field of type float64, Go would do the right thing and produce a
float64(1) value.

[...]

-- 
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