Re: [Json] Interop problem report with number nasties

Carsten Bormann <cabo@tzi.org> Sun, 22 September 2013 07:31 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 119F521F9E02 for <json@ietfa.amsl.com>; Sun, 22 Sep 2013 00:31:17 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.505
X-Spam-Level:
X-Spam-Status: No, score=-105.505 tagged_above=-999 required=5 tests=[AWL=-0.744, BAYES_05=-1.11, HELO_EQ_DE=0.35, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NHi3eyPxrLJ3 for <json@ietfa.amsl.com>; Sun, 22 Sep 2013 00:31:05 -0700 (PDT)
Received: from informatik.uni-bremen.de (mailhost.informatik.uni-bremen.de [IPv6:2001:638:708:30c9::12]) by ietfa.amsl.com (Postfix) with ESMTP id D140E21F9E01 for <json@ietf.org>; Sun, 22 Sep 2013 00:31:04 -0700 (PDT)
X-Virus-Scanned: amavisd-new at informatik.uni-bremen.de
Received: from smtp-fb3.informatik.uni-bremen.de (smtp-fb3.informatik.uni-bremen.de [134.102.224.120]) by informatik.uni-bremen.de (8.14.4/8.14.4) with ESMTP id r8M7Uwqw001605; Sun, 22 Sep 2013 09:31:01 +0200 (CEST)
Received: from [192.168.217.105] (p5489315D.dip0.t-ipconnect.de [84.137.49.93]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by smtp-fb3.informatik.uni-bremen.de (Postfix) with ESMTPSA id 5B76DF8F; Sun, 22 Sep 2013 09:30:58 +0200 (CEST)
Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\))
Content-Type: text/plain; charset="iso-8859-1"
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <CAHBU6isWhqX=_cnfv+n2odkeFKjywH43nR9ASpKUwBWhq3qiLA@mail.gmail.com>
Date: Sun, 22 Sep 2013 09:30:57 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <2589A1DC-2DF8-464A-B5B8-2A6312BAA184@tzi.org>
References: <CAHBU6isWhqX=_cnfv+n2odkeFKjywH43nR9ASpKUwBWhq3qiLA@mail.gmail.com>
To: Tim Bray <tbray@textuality.com>
X-Mailer: Apple Mail (2.1510)
Cc: "json@ietf.org" <json@ietf.org>
Subject: Re: [Json] Interop problem report with number nasties
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.12
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: <http://www.ietf.org/mail-archive/web/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, 22 Sep 2013 07:31:17 -0000

On Sep 22, 2013, at 01:09, Tim Bray <tbray@textuality.com> wrote:

> So encoding a -0.0 in JSON may lead to interoperability problems. 

As with the other number issues, it is not the encoding of a specific value by a sender that leads to an interoperability problem, but the sender relying on a specific interpretation of that value by the recipient.
Here, an interoperability problem would be caused if the sender relies on the recipient preserving the negativeness of the number, or on it differentiating it from a positive zero.

Say, if the required application semantics is that of a lookup table (alist), and a sender sends;

[[-2, "joe"],
 [-1, "jill"],
 [-0, "bob"],
 [0, "jack"],
 [1, "alice"],
 [2, "john"]]

Similar, a sender might rely on the recipient to preserve differences in encoding the same number, such as 0 vs. 0.0 vs. 0e0.  Example:

[[0, "joe"],
 [0.0, "jill"],
 [0.00, "bob"],
 [0e0, "jack"],
 [0e00, "alice"]]

Many programming languages make a strong distinction between NR1 (1) on one hand and NR2 (1.0) and NR3 (1e0) on the other hand.  Since the JSON spec says numbers look like they do in programming languages, inferring that there is a difference between them may be an excusable misinterpretation.  (I don't think anyone would justify relying on distinguishing 0e0 and 0e00, and only very few people would claim that 0.0 clearly differs from 0.00.)

I don't want to beat dead horses, but the interoperability issues come from us not defining the data model, but relying on implementers to pick it up from their background knowledge -- that background knowledge does differ in such details.

Example 2: 1 vs. 1.0.  https://jira.talendforge.org/browse/TDI-26517
is a random example of a bug report highlighting a data model problem.
The bug reporter expected the JSON library to make available to the
application a number as an Integer type independent of whether it was
notated sign-digits only (ISO 6093 "NR1", "integer") or has a decimal
point and/or an exponent (ISO 6093 "NR2/NR3", "real").  They were
rebuffed by the developer stating that JSON numbers notated as "real"s
can't be integers in the decoder's data model.  (Historically, most
programming languages have made such a distinction in number literals.
While RFC 4627 says, "The representation of numbers is similar to that
used in most programming languages.", this is expressly about the
representation, not the data model.)

Grüße, Carsten

PS.: Fun with just two implementations:

>> require 'json'
=> true
>> JSON.load('[-0]')
=> [0]
>> JSON.load('[-0.0]')
=> [-0.0]
>> require 'oj'
=> true
>> Oj.load('[-0]')
=> [0]
>> Oj.load('[-0.0]')
=> [-0.0]

But:

>> Oj.load('[-0e0]')
=> [0]
>> JSON.load('[-0e0]')
=> [-0.0]

So this is an example where
1) the apparent floatingpointness of the number influences the preservation of the negativeness
2) the interpretation of the floatingpointness differs between implementations.