Re: [Json] Another problematic JSON Schema use-case

Tim Bray <tbray@textuality.com> Thu, 26 May 2016 15:56 UTC

Return-Path: <tbray@textuality.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 F01DC12D74C for <json@ietfa.amsl.com>; Thu, 26 May 2016 08:56:09 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.599
X-Spam-Level:
X-Spam-Status: No, score=-2.599 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_LOW=-0.7] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=textuality-com.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 NxKLs-PPbiJF for <json@ietfa.amsl.com>; Thu, 26 May 2016 08:56:08 -0700 (PDT)
Received: from mail-qk0-x229.google.com (mail-qk0-x229.google.com [IPv6:2607:f8b0:400d:c09::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 EDCC712D73C for <json@ietf.org>; Thu, 26 May 2016 08:56:07 -0700 (PDT)
Received: by mail-qk0-x229.google.com with SMTP id y126so60921943qke.1 for <json@ietf.org>; Thu, 26 May 2016 08:56:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=textuality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=yOXs5fLHxg/pFSlho+r4fCTaJCOBLSuOGxlHo3O8Isk=; b=pQrxg7WNElNrfBMvKpl0eQil57+spxZnU+rVkfM2ct6l1DqUD4XyjryZb4mkvdikVO ZBrg8qvfU5ZN9VVstJ7qYJFflzGhK1zfjjpmZ73vObZI0qKkIX+K1koZEngCVcGrkoZq ZL8nCY0w1FU3kGZYbSVoC4GFPGFnzLB7wKm5Xbs21TwdOcPAxrjcMwvQRg14beU845qj AfRzi+Pkb4Zb7aCvkMmAxnMZfZfj4ETdzRrkkYYMDjMpuruuNgWcuBOQkf85QWozuZzH XuIhP2MyH9l5muOLjtY8lsYT2nhr24mPh2XWMfmkjE7isZWsJ0Hm9tl5RQk2EduPviRJ 2cew==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=yOXs5fLHxg/pFSlho+r4fCTaJCOBLSuOGxlHo3O8Isk=; b=Kgqz28E2NynlX1hzMKDG2C6RP+3aNwW/OmLwp73r9TSBO3LSvHBINPxMGs5jz/BZGy 80cJKmbUbONNO4L7ZEEhSCROkkiXLNT6MbSezIujc2aaH0lwRxrEMrxeG2sOi3HA0Mvx HSi2pR72M+2+O1hrS1+qiPxfTNb3t7u2Ywa6D3XvpMHDIVDwCe/QN2hvj7EeQcHZLbfe StJH+dW4K9uSRIyxW9WZd1hiD1n5tiLtEAh8dsmJEqlnHzgWLVAC6lR81q1Icg6ck4ND yJwDldFIQ8YdpsiJr8zgecTE6uf1JTIhjiLR01ZwL3ohWTy75/PuuJEfPjiOD/RoSZRS eZYA==
X-Gm-Message-State: ALyK8tL8xyMKi/xodTtmW/ovDT75A3cChCBO2KrsCkId1YZn0X2YkxoyKMcyS2jlN5CiBu6Dm5wS6X+s2zHYpQ==
MIME-Version: 1.0
X-Received: by 10.200.50.162 with SMTP id z31mr9287453qta.7.1464278167060; Thu, 26 May 2016 08:56:07 -0700 (PDT)
Received: by 10.140.100.215 with HTTP; Thu, 26 May 2016 08:56:06 -0700 (PDT)
X-Originating-IP: [64.141.86.146]
Received: by 10.140.100.215 with HTTP; Thu, 26 May 2016 08:56:06 -0700 (PDT)
In-Reply-To: <CAAQiQRcgKe=V1rmgZnMdQLdJEiftKP1fvbQRG15_AfdAVxqh1A@mail.gmail.com>
References: <CAHBU6ivd5JJ7Hx_JtNPSnW40jXzEF1Yr7=rwuZzGnFrRoMphbg@mail.gmail.com> <CANkuk-WppF4WgeZc5OX2-tozmCd+eYtPwFgmDtoiJHxwdSjDzw@mail.gmail.com> <CAHBU6iu_nYyUBS-8PAJ3zER=RNKfiV532vEOeOnfr5eXbPv8Tw@mail.gmail.com> <CAAQiQRdu2pixrXhuqqmWGjdab6_mCMVcPTKWQQu=Oh0n3MmW0g@mail.gmail.com> <5745EE5E.5050801@tzi.org> <CAAQiQRcgKe=V1rmgZnMdQLdJEiftKP1fvbQRG15_AfdAVxqh1A@mail.gmail.com>
Date: Thu, 26 May 2016 08:56:06 -0700
Message-ID: <CAHBU6iv_ReUfUhP93hy9_npub4nqxoywKtVh65xbc6_DmqDMJw@mail.gmail.com>
From: Tim Bray <tbray@textuality.com>
To: Andrew Newton <andy@hxr.us>
Content-Type: multipart/alternative; boundary="001a11403d540029f80533c0d47b"
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/V00WbKH8VmBa-p6dlX1f8SDWwfo>
Cc: Carsten Bormann <cabo@tzi.org>, json@ietf.org
Subject: Re: [Json] Another problematic JSON Schema use-case
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 15:56:10 -0000

So, to close the loop, here's how I worked around the problem. I
auto-processed my large schema with a Ruby script to generate a small
schema for each of the "Type":"Animal/Vegetable/Mineral" variations, then
if the large schema reports any errors, I run through the objects
validating each with the appropriate micro-schema.  This way, I almost
always get a human-comprehensible error message.

Not optimal, but better than writing a fully procedural validator by hand.
On May 26, 2016 12:00 AM, "Andrew Newton" <andy@hxr.us> wrote:

> On Wed, May 25, 2016 at 8:26 PM, Carsten Bormann <cabo@tzi.org> wrote:
> > Andrew Newton wrote:
> >> It's not too much to ask, but the problem may be with the JSON parser.
> >> Many parsers ingest JSON and give back native data structures, which
> >> is what makes JSON simple for most people. But a validator needs
> >> context that a typical JSON parser does not provide.
> >
> > Can you give an example for that?
> >
>
> Given the following:
>
> [
>   { "foo" : "bar" }
> ]
>
> Here is what happens if I use the built-in Ruby parser:
>
> irb(main):017:0> s
> => "\n[\n  { \"foo\":\"bar\"}\n]\n"
> irb(main):018:0> JSON.parse s
> => [{"foo"=>"bar"}]
>
> If a validator wants to ensure that "foo" is "baz" and not "bar", its
> lost the information to tell the user to look at line 2.
>
> By contrast, if a validator were to use Jackson as a stream parser, it
> would have access to JsonLocation:
>
> http://fasterxml.github.io/jackson-core/javadoc/2.1.0/com/fasterxml/jackson/core/JsonLocation.html
>
> > (I'm familiar with a problem like this from CBOR, where CDDL maybe
> > sometimes wants to make serialization choices*), which are no longer
> > visible at the data model level; I just haven't seen the need with JSON.)
>
> I'm not sure we are talking about the same thing.
>
> -andy
>
> _______________________________________________
> json mailing list
> json@ietf.org
> https://www.ietf.org/mailman/listinfo/json
>