Re: [Json] on serialization of signed zero

Carsten Bormann <cabo@tzi.org> Sun, 05 July 2015 20:08 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 316071A8A50 for <json@ietfa.amsl.com>; Sun, 5 Jul 2015 13:08:49 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: 0.349
X-Spam-Level:
X-Spam-Status: No, score=0.349 tagged_above=-999 required=5 tests=[BAYES_40=-0.001, HELO_EQ_DE=0.35] autolearn=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C3_QdL9iiuIw for <json@ietfa.amsl.com>; Sun, 5 Jul 2015 13:08:48 -0700 (PDT)
Received: from mailhost.informatik.uni-bremen.de (mailhost.informatik.uni-bremen.de [IPv6:2001:638:708:30c9::12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 160111A8A83 for <json@ietf.org>; Sun, 5 Jul 2015 13:08:44 -0700 (PDT)
X-Virus-Scanned: amavisd-new at informatik.uni-bremen.de
Received: from submithost.informatik.uni-bremen.de (submithost.informatik.uni-bremen.de [134.102.201.11]) by mailhost.informatik.uni-bremen.de (8.14.5/8.14.5) with ESMTP id t65K8dxX008839; Sun, 5 Jul 2015 22:08:39 +0200 (CEST)
Received: from alma.local (ip-109-47-3-74.web.vodafone.de [109.47.3.74]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by submithost.informatik.uni-bremen.de (Postfix) with ESMTPSA id 3mPh1K6SmJz3Gt4; Sun, 5 Jul 2015 22:08:37 +0200 (CEST)
Message-ID: <55998EC1.3010309@tzi.org>
Date: Sun, 05 Jul 2015 22:08:33 +0200
From: Carsten Bormann <cabo@tzi.org>
User-Agent: Postbox 4.0.1 (Macintosh/20150514)
MIME-Version: 1.0
To: Sonny Piers <sonny@fastmail.net>, JSON WG <json@ietf.org>
References: <55996D2C.8050907@fastmail.net> <CAMm+LwizHhoYFQJyytKBSXR8Zn_nbiUQBdWxypa3C0NXtF0OUQ@mail.gmail.com>
In-Reply-To: <CAMm+LwizHhoYFQJyytKBSXR8Zn_nbiUQBdWxypa3C0NXtF0OUQ@mail.gmail.com>
X-Enigmail-Version: 1.2.3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/RRT0jWUruScN1oXlgZlTqETivSU>
Subject: Re: [Json] on serialization of signed zero
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sun, 05 Jul 2015 20:08:49 -0000

Phillip Hallam-Baker wrote:
> 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