Re: [Json] A minimal examplotron-style JSON validation language.

Pete Cordell <petejson@codalogic.com> Thu, 30 May 2019 14:39 UTC

Return-Path: <petejson@codalogic.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 2F7D71201C3 for <json@ietfa.amsl.com>; Thu, 30 May 2019 07:39:45 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Level:
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=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 Srv3JCCrsSoi for <json@ietfa.amsl.com>; Thu, 30 May 2019 07:39:42 -0700 (PDT)
Received: from ppsa-online.com (ppsa-online.com [217.199.162.192]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id BCBB0120199 for <json@ietf.org>; Thu, 30 May 2019 07:39:41 -0700 (PDT)
Received: (qmail 26106 invoked from network); 30 May 2019 15:37:40 +0100
Received: from host86-138-183-130.range86-138.btcentralplus.com (HELO ?192.168.1.72?) (86.138.183.130) by lvps217-199-162-217.vps.webfusion.co.uk with ESMTPSA (AES128-SHA encrypted, authenticated); 30 May 2019 15:37:40 +0100
To: John Cowan <cowan@ccil.org>, Nico Williams <nico@cryptonector.com>
Cc: JSON WG <json@ietf.org>
References: <8224451C-F21B-41E5-A834-A9005050CB1F@tzi.org> <CAJK=1RjdYD6TZCNrw=H3d9ZLKLxZZOwVCOYYPwfbP+1ETDDz1Q@mail.gmail.com> <11CDA7F6-30BB-40E4-8926-2EDCBCFD785B@tzi.org> <CAHBU6iv8ZsFM5yco5gi+gcyU8d=u3bOSgiKaF6-hv-GARgNh9w@mail.gmail.com> <CAChr6SwNvG4Z7TKUxAVeH7HMVWiPsEBNb12K9zVkjaGt2_v0fw@mail.gmail.com> <CAHBU6ivTD_v7L-wQ+P9TmSfBY=5N+k-caaZ0TZhg6yZ_SWR_aA@mail.gmail.com> <CAChr6SzD8qdETafQKKU41BcYayTWf+C4GENd9FNzy5JYOv5jRQ@mail.gmail.com> <CAHBU6isx5aB94U-vn_t6GGoQ9W+ATDNYR6_+CtXgOhFho5Qh-g@mail.gmail.com> <20190529144005.GC11773@localhost> <CAD2gp_QELt-3=wqA1gRafNim8Y6fsxZ6hcQmTsoOxCSxU8eM1Q@mail.gmail.com> <20190529201716.GD11773@localhost> <CAD2gp_RmOgea63LeVr36=++nkALa34cvqHbMKXqR7HyzEioBcg@mail.gmail.com>
From: Pete Cordell <petejson@codalogic.com>
Message-ID: <8478bb16-b057-e3af-01f2-dd53a64efb2d@codalogic.com>
Date: Thu, 30 May 2019 15:39:38 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0
MIME-Version: 1.0
In-Reply-To: <CAD2gp_RmOgea63LeVr36=++nkALa34cvqHbMKXqR7HyzEioBcg@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"; format="flowed"
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/zvfVlaW7BOdTvX8FujCQttUpUIU>
Subject: Re: [Json] A minimal examplotron-style JSON validation 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: Thu, 30 May 2019 14:39:51 -0000

On 30/05/2019 13:53, John Cowan wrote:
> On Wed, May 29, 2019 at 4:24 PM Nico Williams <nico@cryptonector.com 
> The question is, where do you stop?  Range constraints are all very well,
> but suppose you want to constrain a number value to be a U.S shoe size,
> which is either an integer (in a certain range) or an integer plus 0.5?

The JCR solution to this type of problem is to be able to have an 
annotation that associates a URI with a primitive type to indicate it's 
internal format. e.g.

    "size" : @{format org.iso.shoe-size} string,

(http://json-content-rules.org/drafts/json-content-rules-10.html#rfc.section.6.11.6)

As far as JCR is concerned, this merely captures the format of the data. 
Whether it's the low-level validators job to validate the type or 
higher-layer functionality is a decision for the individual 
implementation's developer(s).

Same with strings specified with regular expressions. The validator can 
just treat it as a string and leave it to a higher layer, or it can be a 
deluxe validator and check the pattern matches.  (The latter might be 
more useful for a generic on-the-wire monitoring type scenario.)

> What is more, the valid values of one field often depend on the actual
> value of one or more other fields, and so you end up designing a whole
> (functional) programming language.

We had a play with that sort of thing. Mainly as a proof-of-concept that 
the extensibility enabled by JCR's feature had sufficient mileage in it.

http://json-content-rules.org/drafts/draft-cordell-jcr-co-constraints-00.txt

> But in general we expect JSON to be consumed by a program written
> in some such language anyway.  So we might as well decode all numbers
> as double floats, since you can only count on that much precision and
> range anyway, and leave subtypes of number to general-purpose validation.
> By the same token, I don't see that it makes sense to put a whole
> regular expression subsystem into the validator when it can often
> be expressed much more clearly in code (especially in languages
> that have a combinator rather than a string representation of
> regular expressions).

In addition to code, I think a key 'parser' of schemas is human 
developers. That's why we wanted JCR compact and concise. If the human 
developer is able to immediately see the constraints in the schema, and 
not have to wade through pages of prose, I think things are likely to 
work much better.

Pete.
-- 
---------------------------------------------------------------------
Pete Cordell
Codalogic Ltd
C++ tools for C++ programmers, http://codalogic.com
Read & write XML in C++, http://www.xml2cpp.com
---------------------------------------------------------------------