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

John Cowan <cowan@ccil.org> Thu, 30 May 2019 12:54 UTC

Return-Path: <cowan@ccil.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 1DBE012014A for <json@ietfa.amsl.com>; Thu, 30 May 2019 05:54:05 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.898
X-Spam-Level:
X-Spam-Status: No, score=-1.898 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=ccil-org.20150623.gappssmtp.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 0rxXpNLD9dUI for <json@ietfa.amsl.com>; Thu, 30 May 2019 05:54:02 -0700 (PDT)
Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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 816B012004F for <json@ietf.org>; Thu, 30 May 2019 05:54:02 -0700 (PDT)
Received: by mail-oi1-x229.google.com with SMTP id q186so4857806oia.0 for <json@ietf.org>; Thu, 30 May 2019 05:54:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ccil-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5HcI0nQLwrQQNY3CvHGtth+Bb+0B0aQDMyTQD7UffO4=; b=eipFWQQoVYsJkeUgYgDoP/ZpYApQ/JdclS+nAbRXH3MFm31gMYCwM5Tp+Oi9Lx1CYu A4YZT8VmDmplWElcjdQGmpM0i33d2q+jeQr5QZb6LfdoSkFAIsbk/q304b4SxgpqCCSz 2lD+Rro+QwkIkTki7IhSSgMCgJ7q3Wsq1TowpG2c3tthwIxepeX+QPlzECH1dZ5TPzTL bVcCVgAsPIlrSU3SIHfuZeimKEro9IMwMw19JRtDJel4xMMHoDWjDRamjAtpfc9dQ9pZ vNWEtoFmveaIdF6CMb42FswQOBa6JWAzR9CLiAUOILUiRjV2Rrt2t97NvvuSc/IvOfz0 bd1g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5HcI0nQLwrQQNY3CvHGtth+Bb+0B0aQDMyTQD7UffO4=; b=TnrCJwGNJgEjrduw74rdFk5KMgo4CWZVeTtyHtEQZwZ74gooRdD7hZO6nFP7WgiLLV 4GmI8Cih48rmboB21z0jaJjZVMLEzL6sAiibUux2Jrdj5rAAFMBcP8OnN+ZxHtjdghdq Zq2vuHWc6+XDya1KT4oAraNHnH95P7zmParV3He43Ah8ZNlEzfiGtss9WLc1Ch8wEa5S MstSpw+0BrOcMzsh4epx26DAYNAxrdnFGs3Mu907J61WLp/GDqOGbl790Mt78H7+GKPq itkNlR+4QG7UbUcyytB53LSKp8NmZszA1LYNVVK1a3fTLXuTfqeXmBuCLXWVYh7jaz2e iLWA==
X-Gm-Message-State: APjAAAVOg1WtE3KQavDbVYWSgpHb37Rb74xZR3VhRF4tm/EQXuVckTrh MYeXcsVW0fAPqJoBg3j2DEiHa3V+CgHrs0nRmFbTzQ==
X-Google-Smtp-Source: APXvYqyPCX4YL59HUyTkPEJ5zGmO8C+MaThbvFImnGcN7wjb1Ofi9ZNnUmAHmgGposhSph4WAOS+tS2Vc6Nq0nXP6Zs=
X-Received: by 2002:aca:e50d:: with SMTP id c13mr510046oih.42.1559220841471; Thu, 30 May 2019 05:54:01 -0700 (PDT)
MIME-Version: 1.0
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>
In-Reply-To: <20190529201716.GD11773@localhost>
From: John Cowan <cowan@ccil.org>
Date: Thu, 30 May 2019 08:53:50 -0400
Message-ID: <CAD2gp_RmOgea63LeVr36=++nkALa34cvqHbMKXqR7HyzEioBcg@mail.gmail.com>
To: Nico Williams <nico@cryptonector.com>
Cc: Tim Bray <tbray@textuality.com>, JSON WG <json@ietf.org>, Carsten Bormann <cabo@tzi.org>, Ulysse Carion <ulysse@segment.com>, Rob Sayre <sayrer@gmail.com>
Content-Type: multipart/alternative; boundary="00000000000061f95a058a1a6434"
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/vQ7P1p1p-zyDCsyFLirb1FryytU>
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 12:54:05 -0000

On Wed, May 29, 2019 at 4:24 PM Nico Williams <nico@cryptonector.com> wrote:

 - if, where you expect an array you see a boolean, that's an error
>

Agreed,, because statically typed programming languages can't cope.


> - where you expect a numeric value you might have some constraints
>    (e.g., range constraints) that, again, should raise an error if not
>    met
>

>  - ditto strings ('must be bas64', 'must be one of these (enum)', 'must
>    match some regexp', etc.).


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?
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.

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).

Actually, I'll amend my proposal to inclde integers, given how
important they are.  This is easily accomplished by using, say,
0 (equivalently 0.0) to designate an integer and 0.5 to designate a float.)

Using JSON itself as the language for the schema is nice because
> you don't need to build a partser for the schema.  But it's not very
> nice for users, so I'd prefer to have some non-JSON syntax for the
> schema.
>

I don't care about the syntax, but examplotron-style (in which a
type designation is an instance of what it designates) is a strong
design constraint, which is why I adopted it.  I have no problem
with a BNF-style syntax for practical use, like RNG compact syntax.


John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
Assent may be registered by a signature, a handshake, or a click of a
computer
mouse transmitted across the invisible ether of the Internet. Formality
is not a requisite; any sign, symbol or action, or even willful inaction,
as long as it is unequivocally referable to the promise, may create a
contract.
       --Specht v. Netscape