Re: [Json] JSON Schema Language

Nico Williams <nico@cryptonector.com> Mon, 06 May 2019 19:25 UTC

Return-Path: <nico@cryptonector.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 0364A1200E6 for <json@ietfa.amsl.com>; Mon, 6 May 2019 12:25:04 -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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=cryptonector.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 3tNIHfcGP0UJ for <json@ietfa.amsl.com>; Mon, 6 May 2019 12:25:01 -0700 (PDT)
Received: from bonobo.maple.relay.mailchannels.net (bonobo.maple.relay.mailchannels.net [23.83.214.22]) (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 5B14F120126 for <json@ietf.org>; Mon, 6 May 2019 12:25:01 -0700 (PDT)
X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com
Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 1E7F6126929; Mon, 6 May 2019 19:25:00 +0000 (UTC)
Received: from pdx1-sub0-mail-a85.g.dreamhost.com (unknown [100.96.20.60]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A55251266B1; Mon, 6 May 2019 19:24:59 +0000 (UTC)
X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com
Received: from pdx1-sub0-mail-a85.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.2); Mon, 06 May 2019 19:25:00 +0000
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com
X-MailChannels-Auth-Id: dreamhost
X-Wide-Eyed-Duck: 23f077d82e0c4ce4_1557170699901_9774490
X-MC-Loop-Signature: 1557170699901:538270888
X-MC-Ingress-Time: 1557170699900
Received: from pdx1-sub0-mail-a85.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a85.g.dreamhost.com (Postfix) with ESMTP id 5BFCC8096E; Mon, 6 May 2019 12:24:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cryptonector.com; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to:content-transfer-encoding; s= cryptonector.com; bh=ATpiwO5PH54LYRwj8DMAzmiUtZM=; b=tZZeq7pvakw ZxvyNd1okUrwx2he6tkCvYIx9Nm0p38oy5X8pA4COH3Eu1o6s3qycpkG38SX3xN3 CJanYmXn55InsjLgrbrGD3wd9uYLRQs/KOg6Aej3tYJD4rfP4iS6Aq5wlASk4BCl bD7OR+tFGYBXwb+Vt2aibc4sHb8/+gwU=
Received: from localhost (unknown [24.28.108.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a85.g.dreamhost.com (Postfix) with ESMTPSA id E1B8680972; Mon, 6 May 2019 12:24:56 -0700 (PDT)
Date: Mon, 06 May 2019 14:24:54 -0500
X-DH-BACKEND: pdx1-sub0-mail-a85
From: Nico Williams <nico@cryptonector.com>
To: Carsten Bormann <cabo@tzi.org>
Cc: Austin Wright <aaa@bzfx.net>, json@ietf.org
Message-ID: <20190506192453.GK21049@localhost>
References: <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> <40f80ea0-d130-3f3b-39fa-2c84e802ed55@gmail.com> <35E2623E-753D-4918-8AF4-BF0BC5DE4868@bzfx.net> <6260354b-aca2-e001-7145-148b32658416@gmail.com> <9D90C1F1-6747-4373-93B0-8D51C5B25F1C@bzfx.net> <751DAC92-D70C-4C5E-9C61-954D6E300A1F@tzi.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
In-Reply-To: <751DAC92-D70C-4C5E-9C61-954D6E300A1F@tzi.org>
User-Agent: Mutt/1.9.4 (2018-02-28)
X-VR-OUT-STATUS: OK
X-VR-OUT-SCORE: -51
X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduuddrjeekgdeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenogfuuhhsphgvtghtffhomhgrihhnucdlgeelmdenucfjughrpeffhffvuffkfhggtggugfgjfgesthekredttderjeenucfhrhhomheppfhitghoucghihhllhhirghmshcuoehnihgtohestghrhihpthhonhgvtghtohhrrdgtohhmqeenucffohhmrghinhepghhithhhuhgsrdhiohenucfkphepvdegrddvkedruddtkedrudekfeenucfrrghrrghmpehmohguvgepshhmthhppdhhvghloheplhhotggrlhhhohhsthdpihhnvghtpedvgedrvdekrddutdekrddukeefpdhrvghtuhhrnhdqphgrthhhpefpihgtohcuhghilhhlihgrmhhsuceonhhitghosegtrhihphhtohhnvggtthhorhdrtghomheqpdhmrghilhhfrhhomhepnhhitghosegtrhihphhtohhnvggtthhorhdrtghomhdpnhhrtghpthhtohepnhhitghosegtrhihphhtohhnvggtthhorhdrtghomhenucevlhhushhtvghrufhiiigvpedt
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/Zc-OpfBvbmDQWhZ9iU_ZfjwtwCY>
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: Mon, 06 May 2019 19:25:04 -0000

On Mon, May 06, 2019 at 09:32:13AM +0200, Carsten Bormann wrote:
> On May 6, 2019, at 09:22, Austin Wright <aaa@bzfx.net> wrote:
> > But also, why not build a parser that uses a schema to influence how
> > values are parsed?

Because some of us have generic parsers with associated DSLs and we
don't want to be left out.

Specifically, in my case, jq https://stedolan.github.io/jq -- something
of an XSLT/XPath for JSON.

It's perfectly reasonable to build a jq application that adheres to a
JSON schema, but it's not reasonable to expect the jq encoder to know to
do encoding in context-specific ways -- the jq encoder is too generic
and divorced from the rest of the jq machinery to possibly be able to do
that.

By pursuing a schema design that requires context-specific parsing or
encoding behaviors, though you could say that the result looks like
JSON, it precludes use of existing JSON tooling such as jq.

Substitute ECMAScript for jq if you like -- the result is the same.

I strenuously object to this sort of schema.

As a maintainer of jq, I wouldn't know what to say to users who then
complain about non-interop with such a schema other than to point to
this thread and blame the people who allowed it to happen.  But the
damage to jq would be real and unavoidable.  To avoid that damage, if I
cannot convince you, then I assure you that I would appeal any finding
of consensus for such a schema design.

I'm sorry, but 10.0 is perfectly acceptable as an integer, and MUST be
accepted as an integer when you expect an integer even if the JSON RFC
says encoders SHOULD NOT include zero fractional parts.

I would suggest that if you have a schema that says "and this is an
integer", the schema MUST accept zero fractional parts, and SHOULD let
you specify what to do if a non-integer real number is parsed for that
field (e.g., truncate the fractional part, floor, round).

> That is exactly what most of the members of this WG are afraid of when
> the talk comes to “schemas”.

+1

> XML (and later JSON) learned one thing from the problems of SGML:
> schema-oblivious decoders are more robust than schema-depending ones.
> (They are, in the first place, and protocol evolution only amplifies
> this.)

Not only that!

Can you imagine using XSLT/XPath if some XML schema requires different
parsing behavior for different elements?!  It wouldn't be possible to do
that *and* still be able to use XSLT/XPath because XSLT/XPath processors
generally have a built-in generic XML parser.  It would destroy the
utility of XSLT/XPath!

And that proves that an XML schema of that sort... would yield something
that is NOT XML, but merely looks like XML.

The same exact reasoning applies in the case of JSON.  The only
difference being that JSON doesn't [yet] have a standard equivalent to
XSLT/XPath, but since generic parsers and encoders exist, and since
node.jq, JavaScript, ECMAScript, jq, and such exist, the point stands.

> > Suppose you have a dynamically typed language, and want to parse
> > some value, e.g. sometimes as an int, sometimes as a bignum,
> > depending on the property. You might provide a JSON Schema to
> > specify this behavior.
> 
> There goes the generic decoder.
> 
> (There is nothing wrong with using a “schema” to specify upconversion
> from the JSON data model to your application data model.  What I’m
> objecting to is getting rid of JSON and replacing it with a gazillion
> dialects that happen to be syntactically compatible with JSON but the
> semantics of which are controlled by a “schema” mechanism.)

+1.

Nico
--