[Json] Schema for config files Re: Human JSON (Hjson)

Phillip Hallam-Baker <ietf@hallambaker.com> Thu, 26 May 2016 16:31 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 F249A12D753 for <json@ietfa.amsl.com>; Thu, 26 May 2016 09:31:45 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.4
X-Spam-Level:
X-Spam-Status: No, score=-2.4 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.198, 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 TZbYZyttavzz for <json@ietfa.amsl.com>; Thu, 26 May 2016 09:31:44 -0700 (PDT)
Received: from mail-qk0-x235.google.com (mail-qk0-x235.google.com [IPv6:2607:f8b0:400d:c09::235]) (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 1A21212D75A for <json@ietf.org>; Thu, 26 May 2016 09:31:44 -0700 (PDT)
Received: by mail-qk0-x235.google.com with SMTP id x7so61583951qkd.3 for <json@ietf.org>; Thu, 26 May 2016 09:31:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to; bh=iEsNONXZEOVewWhT7VFrfCFFLsDz6xpGb9YZOSMp6jo=; b=lHoVHW7PiDuljXtBPqJnaFlIbY0R1VLrsXOYcryY6Szt4et0ntK/7dxJqfDv7l31LI ihDghpABI8TPcv8uAe35D21veS56jNdZ3BPw++G4IEEqvxJ38VpgK+uiVaJHBfv70JPk XjEpP4Ddb/iLxHYDf/zEDniuTFTKAQ63MV3fUPWyTUMNCj4AjCXw4jNaZ4gJmLjyQjN8 9iTEYrUmDJeXxDBosMhvCG6M3DQE242s8aTR7O4HmK2qDwhrCdSEcSOjb2VgGyuMQXqo kygZ25wJ4dK1/SYv7/xvfC83PlXrq6KgMrS2P3FCH0YaOZh7MGSWDYYTXONgPdoj1hxc V47Q==
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:date:message-id:subject:from :to; bh=iEsNONXZEOVewWhT7VFrfCFFLsDz6xpGb9YZOSMp6jo=; b=i1WocoR/eODH5/aqy3891Y9EkdD1S+nW4iBYK+6hJJzAWNPS6Uqye6msRt9CDgxe5u 9RZvUsa2vMg1nZTRxAyP7GhV4XzQvpuaGNtQUjq77JdQJgxS6xVaNHgXZxIAY/OzYdUo zH/eqa0cBHqApImIAnW8ZFZcF7hUlx0ZdX4FPM9m+gUqz82xTCxTet8/Z5W3cdsUs4jl srqA4T7z63skIjBxSpFl8VbKV90hUFL2bOxpdNQ+jeltFxwdthE/jTsoJbODpe2oaZKE kuhGh11pWyQWI999AxCIcQVN1OKA1Wmk0lcYX6fGjYZRLNqfzuyXqWgnldMcaHGmT9St oSow==
X-Gm-Message-State: ALyK8tImsY70Xhw1AZTIifHKjuP5BypaZVaLdGFUgvHEPmX6jKrnqYuIoUk3akd4kxAcZgQV6GjGByA1zQU5tw==
MIME-Version: 1.0
X-Received: by 10.55.114.71 with SMTP id n68mr10059478qkc.37.1464280303118; Thu, 26 May 2016 09:31:43 -0700 (PDT)
Sender: hallam@gmail.com
Received: by 10.55.25.85 with HTTP; Thu, 26 May 2016 09:31:43 -0700 (PDT)
Date: Thu, 26 May 2016 12:31:43 -0400
X-Google-Sender-Auth: hIBfjVHeMNO0PATwEOeFVDHje2I
Message-ID: <CAMm+LwjmR7JnhkoOKsYRhVLR5DJ5r=mLP+uoOTjGOgKx_zi-5Q@mail.gmail.com>
From: Phillip Hallam-Baker <ietf@hallambaker.com>
To: JSON WG <json@ietf.org>
Content-Type: multipart/alternative; boundary="001a114fef8a51b07c0533c1537e"
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/Av7JK_XhQ-e9VKczpdjakCI1PyA>
Subject: [Json] Schema for config files Re: Human JSON (Hjson)
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: Thu, 26 May 2016 16:31:46 -0000

It isn't on topic for the encoding discussion, but is for the schema we
keep discussing.

Over the past 20 odd years I have designed a lot of languages. At least 30.
And about a dozen of those look very much like a schema sort of language.

All that my Goedel tool is, is a front end that allows me to quickly create
a parser that reads an input file and converts it to a DOM like tree and a
back end that is simply a scripting language that then expands it.

This is a very powerful way to code if you want to write stuff quickly.

The one thing that I have in Goedel that isn't in the JSON schemas I have
seen is that I have a 'Label' construct similar to an XMLSchema ID. Labels
are very useful in Goedel because the parser automatically links them in
both directions.

If I specify a label 'Foo' in one part of the input file, the parsed data
structure will have a list of links to every part of the data structure
that references it. (And vice versa of course).


This is very useful in config files because it allows you to do things like
specify the parameters for a network connection in one place and then
instantiate it in multiple places.

I don't see any need to specify ranges on integers, number of sub items
that can appear or anything of that sort. But labels are very very powerful.


The other thing that I have found I want but never implemented is to have
the backing structure automatically collect up references to lists of
options.

So in my current UI scheme I have a UI that can contain a list of Wizards,
Dialogs, menus and such. [NB, the convention here is label follows type,
something else I would like to fix some day]

GUI MyUI
   Wizard CreateProfile
       ... wizard def
   Menu MainMenu
   Dialog Print
   Dialog Exit

So right now, the backing structure in C# is

class GUI : Object {
    Label Name;
    List <Object> Entries;
    }

Which is OK only my scripting language then ends up being full of code to
filter on particular types of entry. A better scheme would be:

class ObjectSet {
    List <Object> Object;  // All objects
    List <Wizard > Wizard  ;  // filtered to Wizard
    List <Menu> Menu ;
    List <Dialog> Dialog ;
    ...
    }

class GUI : Object {
    Label Name;
    ObjectSet Entries;
    }

Supporting a JSON like serialization properly would be fairly
straightforward. I would just have to work out how to redesign the parser
so that the object name always precedes the object data. Which is the JSON
way and actually a better way to do things:

MyUI GUI
   CreateProfile Wizard
       ... wizard def
   MainMenu Menu
   Print Dialog
   Exit Dialog

The reason this is better is that a label is always an atom whereas a type
can have parameters.

I suspect that what it would take is to distinguish between objects and
structures. The difference being that an object always has an identifier
and can be the target of a label and a structure does not.

class Object {
    Label Name;
    }

class GUI : Object {
    ObjectSet Entries;
    }