Re: [Json] The names within an object SHOULD be unique.

Allen Wirfs-Brock <allen@wirfs-brock.com> Thu, 06 June 2013 17:45 UTC

Return-Path: <allen@wirfs-brock.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 6F9FE21F9A78 for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 10:45:13 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.737
X-Spam-Level:
X-Spam-Status: No, score=-1.737 tagged_above=-999 required=5 tests=[AWL=-0.261, BAYES_00=-2.599, HELO_MISMATCH_ORG=0.611, HOST_MISMATCH_COM=0.311, HTML_MESSAGE=0.001, J_CHICKENPOX_35=0.6, J_CHICKENPOX_45=0.6, RCVD_IN_DNSWL_LOW=-1]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WXzhkqUgwy1J for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 10:45:07 -0700 (PDT)
Received: from smtp.mozilla.org (mx2.corp.phx1.mozilla.com [63.245.216.70]) by ietfa.amsl.com (Postfix) with ESMTP id A490F21F99C7 for <json@ietf.org>; Thu, 6 Jun 2013 10:45:07 -0700 (PDT)
Received: from [192.168.0.15] (069-064-236-244.pdx.net [69.64.236.244]) (Authenticated sender: allenwb@mozilla.com) by mx2.mail.corp.phx1.mozilla.com (Postfix) with ESMTPSA id B35D6F20CA; Thu, 6 Jun 2013 10:45:06 -0700 (PDT)
Mime-Version: 1.0 (Apple Message framework v1085)
Content-Type: multipart/alternative; boundary="Apple-Mail-43--756005511"
From: Allen Wirfs-Brock <allen@wirfs-brock.com>
In-Reply-To: <DA7A83A2-1C1F-4E74-BF6A-DA943B07AB59@vpnc.org>
Date: Thu, 06 Jun 2013 10:45:01 -0700
Message-Id: <C25B2BF6-512F-41CB-A9E8-E329E9C4BDCE@wirfs-brock.com>
References: <51AF8479.5080002@crockford.com> <51AF9ACF.5020507@cisco.com> <D0A99569-0915-4862-A7AE-9DE51C2E90C0@yahoo.com> <51AFB3F8.8060708@crockford.com> <8F32953C-C788-4DC9-888E-920E2BEB7FDD@yahoo.com> <831B8E46-F239-4353-8F95-8DF3F9BD2E78@yahoo.com> <51AFC924.2030805@crockford.com> <DA7A83A2-1C1F-4E74-BF6A-DA943B07AB59@vpnc.org>
To: json@ietf.org
X-Mailer: Apple Mail (2.1085)
Cc: Paul Hoffman <paul.hoffman@vpnc.org>
Subject: Re: [Json] The names within an object SHOULD be unique.
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.12
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: <http://www.ietf.org/mail-archive/web/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: Fri, 07 Jun 2013 16:36:59 -0000

Just got signed on to this list...
(and this message didn't seem to make it there the first time, so sorry if this is duplicated)

There is also a discussion of this topic going on at es-discuss@mozilla.org which I'm trying to redirect here.

My recommendation from the es-disuss thread is below.

Allen Wirfs-Brock
ECMAScript Language Spec. Project Editor


On Jun 6, 2013, at 8:24 AM, Paul Hoffman wrote:

> On Jun 5, 2013, at 4:26 PM, Douglas Crockford <douglas@crockford.com> wrote:
> 
>> If duplicate names are encountered, the parse MAY fail (because some implementations correctly do that), or it MAY succeed by accepting the last duplicated key:value pair.
> 
> The new text should use language that is already in RFC 4627; "key" is not such a word. To be fair to implementers, the new document also needs to deal with both emitters and parsers.
> 
> Proposal:
> 
> In Section 2.2:
> Current:
>   The names within an object SHOULD be unique.
> Proposed:
>   If the names within an object are not unique, the result of parsing the 
>   object is unpredictable, and the parse may even fail completely. Thus,
>   the names within an object SHOULD be unique.
> 
> In Section 4, add a new paragraph:
>   If a parser encounters an object with duplicate names, the parser MAY
>   fail to parse the JSON text; if the parser accepts objects with duplicate
>   names, it SHOULD accept only the last name/value pair that has the
>   duplicate name. 
> 
> --Paul Hoffman

Some that should be pointed out is that one reason JSON needs to accept duplicate field names is that some people currently use them to add  comments to JSON datasets:

{
"//": "This is a comment about my data",
"//":  "that takes more than one line",
"field1" : 1,
"field2" : 2
}

The above is valid according to the existing RFC and is accepted as valid JSON by the existing ECMAScript  JSON.parse spec. We don't want to invalid existing JSON datasets that use this technique so duplicate keys MUST be accepted.

What I would say, as a replacement for the current text  <section 2.2> is:

         The names within an object SHOULD be unique.  If a key is duplicated, a parser MUST take  <<use?? interpret??>> only the last of the duplicated key pairs.

I would be willing to loose the first sentence (containing the SHOULD) entirely as it doesn't add any real normative value.

Given that duplicate names have historically been valid, that some people use them, and that the standard ECMAScript JSON parser accepts them I don't see why allowing a parser to reject duplicate names is helpful.