On Thursday, March 2, 2017 at 12:01:49 PM UTC+1, Jakob Borg wrote:
>
>
> On 2 Mar 2017, at 18:29, Basile Starynkevitch <bas...@starynkevitch.net 
> <javascript:>> wrote:
>
> I would like that second line to be at least json_emit buf: -1.0 because 
> I need to separate objvalmo.FloatV from objvalmo.IntV types
>
>
> 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.
Separating floats & integers is so common in most JSON implementation that 
I believe it is an implicit part of the JSON spec (I know it is not, but 
JSON parsers are distinguishing numbers with or without decimal points). 
Actually, I can't name any JSON implementation confusing integers and 
floats (but of course there might be, it even looks that YoJson might be 
configured as such, but probably is not by default, because int and float 
are different basic types in Ocaml).

 

> That said, since you have custom types you could implement 
> FloatV.MarshalJSON (or MarshalText) and do the formatting there as you 
> please. 
>

Thanks for the hint. Will try that (not very simple for me to understand 
how).

>
> //jb 
>

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