Re: [Json] JSON Schema Language

Anders Rundgren <anders.rundgren.net@gmail.com> Sun, 05 May 2019 05:07 UTC

Return-Path: <anders.rundgren.net@gmail.com>
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 5E4E5120195 for <json@ietfa.amsl.com>; Sat, 4 May 2019 22:07:36 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 Af6PTqkDv8fU for <json@ietfa.amsl.com>; Sat, 4 May 2019 22:07:34 -0700 (PDT)
Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 4B02512012B for <json@ietf.org>; Sat, 4 May 2019 22:07:34 -0700 (PDT)
Received: by mail-wr1-x431.google.com with SMTP id a12so2742821wrn.4 for <json@ietf.org>; Sat, 04 May 2019 22:07:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=KpeMQdK29ZWJn4LHQcYioDKfpam/r/Q3TDkqQTshKSU=; b=tcgXDmBgXFXu8fo3qwKay9m4TJnAyUx7AMOhj8VVWc/6F24XJEQ5RrngQSVO+fYKZh 5BfsXFAUCCtntnwJIrqgnhg7/0qrixaSE6V6D2zW+JF4a+cT5q7+VxuhNhqOS0y1PDY4 VNuR3dSgmMHYzZArVwM4bFrw9MlKLWpazu9GDEOZi9pd5BDueKIC7TmDjpoTeRdTqrxy /ZADPsoRzwBpserZAhHZrbUMhmppwerdIiyHjNeiKJdCLdsZnJwgs+Ewrhh2k42LsxIW jpwO9DEem76tCTYGp4+iMSbD+BZZefPn0bsuEEzqk+SQtf8WkUTLu+/uqw/LjQOeiuS9 Zoow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=KpeMQdK29ZWJn4LHQcYioDKfpam/r/Q3TDkqQTshKSU=; b=efO6jlfpNzwBo773NhtR/ePvKS4Fs2O3dLGhHZu5JEMMFoTe9MuI+9omwqpGF5uw+4 zThX46Ulxa6iRir2zlPHxffDBeqTxJZLL9tGcsJ2RmqyZ6df5av2AjX1UljwfHzm517P n0c30cBDe0NnEk/RcQL093cDXquw25XxJvv+oAzQ9KZAkaFdGkR8Z+0WdBdX3Zz1zhku Sg0WOmdA5cDHpk6erq3293ogfQY7ZZNrLNIDWlUHBFjpa55I6vkQKAfqWuJL+oLBn3t/ ClqfWlueGMmdRCM/pIhpnZ8emWerZ4eVVd+5RBQrYATo0sGEOSlz+CCuR8pzKkzM7wH4 SKNw==
X-Gm-Message-State: APjAAAVjxxzu4n2VA9GQCEpJvRouj4Pm7N7UiWY9R0MaoGeOe6wquGgJ +qCHOvnOtvoj3oKTf5jR3vM0pykwuFU=
X-Google-Smtp-Source: APXvYqzDis9sBXkqlzZxyt2RVHB0ysZRSn7Ny7DX7kmuVbFD8BlR/WwQTx6xAEjqcqxvT+j4w2iLug==
X-Received: by 2002:adf:c748:: with SMTP id b8mr13085975wrh.292.1557032852779; Sat, 04 May 2019 22:07:32 -0700 (PDT)
Received: from [192.168.1.79] (25.131.146.77.rev.sfr.net. [77.146.131.25]) by smtp.googlemail.com with ESMTPSA id j13sm20392147wrd.88.2019.05.04.22.07.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 May 2019 22:07:30 -0700 (PDT)
To: Austin Wright <aaa@bzfx.net>, Carsten Bormann <cabo@tzi.org>
Cc: json@ietf.org, Ulysse Carion <ulysse@segment.com>
References: <CAJK=1RjV1uv0eOdtFZ8cKn-FfCwCiGP5r2hOz1UamiM6YV4H1A@mail.gmail.com> <39682ec8-f993-a44c-d3e2-1638d2c1608f@gmail.com> <29CAE1CE-D6CB-4796-B2F2-2095BE921385@tzi.org> <AD5ABD9C-F5F2-477D-B862-529C890D5472@bzfx.net> <DA1767B8-22D6-4EA9-8112-4B36B79E9039@tzi.org> <D21B379B-23CC-48B3-BE10-D2777308E2E0@bzfx.net>
From: Anders Rundgren <anders.rundgren.net@gmail.com>
Message-ID: <40f80ea0-d130-3f3b-39fa-2c84e802ed55@gmail.com>
Date: Sun, 05 May 2019 07:07:26 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1
MIME-Version: 1.0
In-Reply-To: <D21B379B-23CC-48B3-BE10-D2777308E2E0@bzfx.net>
Content-Type: text/plain; charset="utf-8"; format="flowed"
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/jSXnHbI6DWt8TpdH_mO8ECEPxHU>
Subject: Re: [Json] JSON Schema Language
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.29
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 May 2019 05:07:36 -0000

On 2019-05-05 04:51, Austin Wright wrote:
> 
> 
>> On May 4, 2019, at 02:42, Carsten Bormann <cabo@tzi.org> wrote:
>>
>> Curious:
>>
>> On that web page, it also says “For consistency, integer JSON numbers SHOULD NOT be encoded with a fractional part.”
>>
>> What does that mean?
> 
> It’s a non-normative suggestion with the aim of enhancing performance: Many programming languages distinguish between integers and IEEE floats by the presence of a decimal point. While JSON makes no such distinction (all numbers are arbitrary precision decimal), some parsers do make that distinction, and it’s slightly easier to determine if an int32_t is an integer than if a double is an integer.

in the C# example I provided before this is (by default) not non-normative, since it threw an exception.   Here is a little bit more detail:

class MyObject {
   int Counter;
    .
    .
}

Deserializing JSON into this type (which BTW works as as "schema"), REQUIRES "Counter" data to adhere to normal integer notation, including value span.

A scheme language should align with the actual use and interpretation of JSON.  This involves alternative serialization formats as well.  As an example monetary values are (probably without exceptions) expressed as JSON Strings since floating point is unsuited for decimal arithmetic.

Based on the RFC, one might come to the conclusion that JSON is an inferior information transfer format, but aided by external mapping it actually works extremely well, albeit being slightly verbose :)

Cheers,
Anders

> 
> Cheers,
> 
> Austin.
> 
>>
>> Grüße, Carsten
>>
>>
>>> On May 4, 2019, at 11:36, Austin Wright <aaa@bzfx.net> wrote:
>>>
>>>
>>>
>>>> On May 4, 2019, at 00:58, Carsten Bormann <cabo@tzi.org> wrote:
>>>>
>>>> On May 4, 2019, at 06:47, Anders Rundgren <anders.rundgren.net@gmail.com> wrote:
>>>>>
>>>>> Example: although 10.0 is a valid JSON Number, in system where you expect
>>>>> an integer, this should be flagged as a syntax error.
>>>>
>>>> 10.0 is an integer number.
>>>>
>>>> “Schema Languages” operate at the data model level.  In the JSON data model, there is only one kind of number.
>>>> Of course, the JSON data model is not actually defined in a standard, which is one of the major shortcomings of JSON.
>>>>
>>>
>>> JSON Schema handles this exactly the same way, defining a data model [1]. The lexical representation is surjective onto the data model: as you point out, 10.0 is the same as 10, which is an integer.
>>>
>>> The one case where this might fall apart is if significant digits are important, such that 10.0 is different than 10.00 (i.e., 10.00 is more precise by an order of magnitude). However, I’m not aware of any JSON parsers that keep track of the precision of numbers, even ones that support arbitrary precision. I imagine scientific applications would want to store an explicit precision, since they’re not always powers-of-10 (e.g. {value: 32.0, precision: 0.5}).
>>>
>>> [1] http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2.1 "4.2.1. Instance Data Model"
>>>
>>> Austin.
>>
>