Subject: [Json] on serialization of signed zero

From: Sonny Piers <[email-masked]>
Date: Sun, 05 Jul 2015 19:45:16 +0200

Hello,

Signed zeros are included in the IEEE floating point standard.
 From my understanding RFC 7159 doesn't forbid them.
But both python and ECMAScript serialize signed zeros (-0) into "0".

I wonder what would be the correct way of serializing them.

Thanks.

---

From: Phillip Hallam-Baker <[email-masked]>
Date: Sun, 5 Jul 2015 14:54:05 -0400

Same as NaN, you can't.

I propose extending JSON with a binary encoding for that exact reason and
to allow the precision of binary numbers to be preserved. But this could
also be done using Hex.

On Sun, Jul 5, 2015 at 1:45 PM, Sonny Piers <[email-masked]> wrote:

> _______________________________________________
> json mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/json
>
>

---

From: Carsten Bormann <[email-masked]>
Date: Sun, 5 Jul 2015 20:57:01 +0200

http://www.ietf.org/mail-archive/web/json/current/msg01661.html

(And the whole thread around that.)

Grüße, Carsten

On 5 Jul 2015 at 19:52:31, Sonny Piers ([email-masked]) wrote:

Hello,

Thanks.

---

From: Tim Bray <[email-masked]>
Date: Sun, 5 Jul 2015 12:51:58 -0700

I think the best practical advice is: Do whatever will produce the least
surprise after round-tripping through JavaScript.

---

From: Carsten Bormann <[email-masked]>
Date: Sun, 05 Jul 2015 22:08:33 +0200

> Same as NaN, you can't.

Not the same.

There is no representation for NaN in JSON.
(The usual recommendation is to substitute `null`.)
The reason is as arcane as it is frustrating:
JavaScript handles NaN etc. using variables, so there is no syntax in
the JavaScript value notation that became JSON.

There are a number of representations for negative zeros.

JavaScript can even properly parse and decode them, e.g.:

JSON.parse("-0")
-0

It just can't roundtrip them:

JSON.stringify(-0)
"0"

So if it is indeed important for you to be able to roundtrip negative
zeros through JavaScript, you'll need to invent something.
Such as representing negative zero by a string, "-0".
(JavaScript can roundtrip those, but of course you are on your own in
decoding them.)

Grüße, Carsten