Re: [Json] Call for real-world examples of how parsers deal with duplicate keys

Stephan Beal <sgbeal@googlemail.com> Thu, 06 June 2013 19:50 UTC

Return-Path: <sgbeal@googlemail.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 C2D0A21E80B0 for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 12:50:11 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.008
X-Spam-Level:
X-Spam-Status: No, score=-1.008 tagged_above=-999 required=5 tests=[AWL=-0.323, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622, HTML_MESSAGE=0.001, MISSING_HEADERS=1.292, NO_RELAYS=-0.001]
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 CGOj60CzztiI for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 12:50:07 -0700 (PDT)
Received: from mail-wg0-x22f.google.com (mail-wg0-x22f.google.com [IPv6:2a00:1450:400c:c00::22f]) by ietfa.amsl.com (Postfix) with ESMTP id 69CEC21E80A7 for <json@ietf.org>; Thu, 6 Jun 2013 12:50:07 -0700 (PDT)
Received: by mail-wg0-f47.google.com with SMTP id e11so2415101wgh.2 for <json@ietf.org>; Thu, 06 Jun 2013 12:50:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=1jArutRvBBDFIT98Zk6c2nyltJr2LE068BJr496vHC8=; b=f8zKOjm+5QWl7xtTsdgnVKQ9bfEVRU0cNksxKW7XuqcGnLwJJ/hFgq4yoRV5tDB2XR FdgD9TtCTgTvVXKkF27NpdeZcGn/6/DrPiipbPjlr7O2BaT0T6Yr1pXN8nPJ0ySfu7MB wlR6j3tqpCtdRTt3LrIF1qb6DwFamZMozNTWxmITgwtTwFDOZyu0V9c9GkfKsOX//hrA Wd4cnfw8K/ag8JZqNtOAafT802Qk1dotydAhiKn+Ad3HRjxE28sSH4YuqWmtGWZyXtXy oMQrcMxVa/vA4WK6Boq7Zu/cZPeZXJmBPqWyY2vvk4QPgm7J4Ggz8D68C7lpM3nPxU3x fj0g==
MIME-Version: 1.0
X-Received: by 10.194.179.102 with SMTP id df6mr33445873wjc.42.1370548206520; Thu, 06 Jun 2013 12:50:06 -0700 (PDT)
Received: by 10.194.42.230 with HTTP; Thu, 6 Jun 2013 12:50:06 -0700 (PDT)
In-Reply-To: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org>
References: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org>
Date: Thu, 06 Jun 2013 21:50:06 +0200
Message-ID: <CAKd4nAiduef4zosTt4TgiX__MFK5RM+JC1wSnu0tTT5FznCCLg@mail.gmail.com>
From: Stephan Beal <sgbeal@googlemail.com>
Cc: "json@ietf.org" <json@ietf.org>
Content-Type: multipart/alternative; boundary="089e01493c34ff4f0a04de819ef3"
Subject: Re: [Json] Call for real-world examples of how parsers deal with duplicate keys
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: Thu, 06 Jun 2013 19:50:12 -0000

On Thu, Jun 6, 2013 at 7:41 PM, Paul Hoffman <paul.hoffman@vpnc.org> wrote:

> Greetings again. Knowing what current parsers do with duplicate keys might
> be useful to this discussion. Of course, some people will exclaim "but
> that's wrong!" to some of what we see, but seeing it may be useful
> nonetheless.
>
> I propose the following JSON text for the tests:
>
> {"a":1,"a":2}
>

My C and C++ implementations would result in {"a":2}. That was the only
implementation which made intuitive sense to me (and is faster than
erroring on dupes in the C++ code, which of course uses std::map as the
basis, and avoids me having to search that map to check for a dupe). While
library-level coding effort would not be notably more to error on dupes, it
does add another error case/code for clients to check for, and it just
didn't make sense to me to deal with this (what i consider to be a) corner
case. This approach also, IMO, conforms to the "principal of least
surprise," which for me means "last one wins.'

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal