<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 25, 2012 at 10:42 PM, Richard O&#39;Keefe <span dir="ltr">&lt;<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Note that the conversion *IS* lossy in practice.</div>
If you send a JSON message to a Javascript program,<br>
or a Python program, or a Go program (if I am reading src/pkg/encoding/json/decode.go<br>
correctly) what you get will be a 64-bit float.<br>
The Jackson parser for Java uses Double for numbers with a &#39;.&#39; or &#39;e&#39; by default,<br>
although it can be configured to use BigDecimal.<br>
<br>
If you want numbers outside the domain of finite 64-bit floats to travel<br>
unscathed through JSON, then you must control not only which languages are<br>
used at each end, but which versions of which libraries and how configured.<br>
<br></blockquote><div><br></div><div>Right, for better or for worse, the absence of numeric semantics in the JSON standard means that what a number means is up to the implementation(s) involved, and the onus is on the user(s) to coordinate between them.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I argued the other end of this in the mailing list for another language,<br>
saying that I wanted things that look like integers to be decoded as integers,<br>
and was stepped on hard.  Some people found their programs much simpler if<br>
they always got the same kind of Number whatever the input looked like (in<br>
Jackson, a Number might be returned as an instance of any of five classes).<br></blockquote><div><br></div><div>My view is that the only reasonable approach is to decode JSON numbers into arbitrarily-sized rationals, such that interpretation is arguably lossless (modulo loss of precision, if e.g. 1.0 cannot be distinguished from 1).</div>
<div><br></div><div><br></div></div>Alvaro</div>