Re: [Json] Schemas & so on

Phillip Hallam-Baker <ietf@hallambaker.com> Tue, 03 May 2016 20:03 UTC

Return-Path: <hallam@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 63DCF12D838 for <json@ietfa.amsl.com>; Tue, 3 May 2016 13:03:13 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.399
X-Spam-Level:
X-Spam-Status: No, score=-2.399 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.199, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, 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 ZCdY64KWMiRJ for <json@ietfa.amsl.com>; Tue, 3 May 2016 13:03:10 -0700 (PDT)
Received: from mail-qg0-x22e.google.com (mail-qg0-x22e.google.com [IPv6:2607:f8b0:400d:c04::22e]) (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 4DA8912B03A for <json@ietf.org>; Tue, 3 May 2016 13:03:10 -0700 (PDT)
Received: by mail-qg0-x22e.google.com with SMTP id 90so13589555qgz.1 for <json@ietf.org>; Tue, 03 May 2016 13:03:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=dtv9kd8ku5/4sEOaeQpd4kq/65II17m0j4nHxhPZ0aA=; b=SyMFUaZ1aBaP1n70V2DXE2FTRyMXjBPc4tmPKZD2lNvhju/opU0yI4PKmMgYNBJ4zB DcIfbnwJIThtjVqlPltOH+GjEZOs4a0wZaem3OR07i91FOvybMbST5YlAPOeqQsBK7ov Qru8d7PvCmWfZJL9DV8uLfv2hbuNRxFeWj36PbihBk/89Mz+zTBZx6AHVAyZ+7TI6eBQ yFahLRBevA8s8wnJch5IknM/FbTNF29C9edbdeRoFo+/bcgiQLzly8M8vBKz7PWQ3Aoj U7Wo+6tDn/8nwP+iPugWAwC8hqlhFG7l65dSOESSXXv6iCS4Ypn+DpR43HGYdG08aHjD CoXg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=dtv9kd8ku5/4sEOaeQpd4kq/65II17m0j4nHxhPZ0aA=; b=L/Txy+eVUbefJmK+fsJo4wizDveh0AJ1q88KRc3eUYBGdNXvIfD/dyReIPTa93e1Xk TQLmkGYMGxxNwMsabJirMN0pgfw+yX27CKbxnvko0md9PrQLDMojMBJf4ph81KY9iU1E 0LzfngwvxcqyAIzaAkU3pO8JdY33ED4V7D80MpIChPxbO6dzizx7kYBkUtSJq7YsHB4J Z0tU0c5wFS1Zs7Xf+HSGYNV7NYG8tWqjiWOj/Ppah1C7qCAk6hp9I5KzC1+J+EJ+GuT1 zXDzX4PLsbMNMOh0cebliEDSy9GGHYaSWPVDqYOYk/HcAxkhPU2Tve8eHX+Fnt7vgvjO QPDA==
X-Gm-Message-State: AOPr4FV875F/b64XWBlTy7VsT6e5oEE5yIE648nSf9OgGQuyGwV9oWrMKpGp3rIBERAfZhCy5CVV+GtV4SMafA==
MIME-Version: 1.0
X-Received: by 10.140.18.114 with SMTP id 105mr4678485qge.41.1462305782107; Tue, 03 May 2016 13:03:02 -0700 (PDT)
Sender: hallam@gmail.com
Received: by 10.55.24.38 with HTTP; Tue, 3 May 2016 13:03:00 -0700 (PDT)
In-Reply-To: <20160503195037.GC6756@mercury.ccil.org>
References: <CAHBU6itCV9MXmALdKtE9-vjUPG6-6ZqdqzrmZkcEzSUysi3S-w@mail.gmail.com> <AC93811D-A16A-4527-B2EB-C6A9FC6D4F17@mnot.net> <CAHBU6iuxaoXvNncw5_8uNaKf5zi+JEw3xhmA_iPN6OVWc+xCcQ@mail.gmail.com> <CAMm+Lwh0TfOuU5dXMAnY8YP1QHHTwhZs2mkgdbjcQ7sLukSX8w@mail.gmail.com> <20160503190957.GB6756@mercury.ccil.org> <CAMm+LwjWhO3zJcE+ktjJNh82D0_P5hH-=u_tYPus50Y7H2Vx=g@mail.gmail.com> <20160503195037.GC6756@mercury.ccil.org>
Date: Tue, 03 May 2016 16:03:00 -0400
X-Google-Sender-Auth: dZ48tbUKRIbfKWJ9YWkyHF1STbw
Message-ID: <CAMm+Lwh=Ms8-sfurHVJbA9iG-4xx-DJ92kFwyWJHvGAzNQOQiw@mail.gmail.com>
From: Phillip Hallam-Baker <ietf@hallambaker.com>
To: John Cowan <cowan@mercury.ccil.org>
Content-Type: multipart/alternative; boundary="001a11c03f7ebb793c0531f598b9"
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/byHd7mmFhDdmLMCMCUfdcGxMePE>
Cc: Mark Nottingham <mnot@mnot.net>, Tim Bray <tbray@textuality.com>, "json@ietf.org" <json@ietf.org>
Subject: Re: [Json] Schemas & so on
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.17
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: Tue, 03 May 2016 20:03:13 -0000

On Tue, May 3, 2016 at 3:50 PM, John Cowan <cowan@mercury.ccil.org> wrote:

> Phillip Hallam-Baker scripsit:
>
> > 1) Order in which the elements appear.
>
> My understanding is that people do use JSON arrays this way: the first
> element means X, the second means Y.  If arrays are always or almost
> always used in a uniform way, then we don't have to worry about order,
> just specify a single type type for all the individual elements.
>
> > 2) alternatives
>
> No cases of number-or-string, or object-or-null?
>

I don't allow number or string or see the need.

For all fields I allow the following

Minimum Occurrences = 0 or 1
Maximum Occurrences = 1 or unlimited.

Null is only allowed if the Minimum Occurrences is 0. If Max is unlimited
then the field maps to a list rather than a simple variable and the
corresponding serialization is an array.

That is possibly too strict as right now going from max occurs 1 to
unlimited breaks backwards compatibility as the serialization changes from
item to array[item]. I could probably be loser there.


There might be an argument to be made for any 'Any' field type which can
contain anything. I don't support that right now. But I might have to
rejigger my parser if I am supporting ACME and they don't go to the nested
approach.

ACME has the following type system, lets say you are sending a Delete
request, an acceptable message serialization would be:

{ "field1" : "data",
 "field2" : "data",
 "field3" : "data",
 "type" : "Delete",
 "field4" : "data",
 "field5" : "data"}

The only way this can be supported is to parse the entire JSON tree to an
intermediate format and then perform schema processing on the tree. Which
is fine if that is the way you want to do things and you are not writing a
transaction where field1 might be several Gb and so you want to check if
you understand the transaction before accepting the data or otherwise
concerned about being practical.


If I have to support the above, I will probably do so by pre-parsing the
tree and so it would be fairly straight forward to support a variant type.

But there would have to be a good reason because it is going to have to be
mapped to a C / C# / Java type sometime.



>
> > 3) model groups
> > 4) the bizaro dual type system in which elments type data and types type
> > elements.
> > 5) Distinguishing attributes and elements
>
> Agreed on those.
>
> --
> John Cowan          http://www.ccil.org/~cowan        cowan@ccil.org
> "But I am the real Strider, fortunately," he said, looking down at them
> with his face softened by a sudden smile.  "I am Aragorn son of Arathorn,
> and if by life or death I can save you, I will."
>