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

Stefan Drees <stefan@drees.name> Thu, 06 June 2013 18:04 UTC

Return-Path: <stefan@drees.name>
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 41E1E21F99D1 for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 11:04:19 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.099
X-Spam-Level:
X-Spam-Status: No, score=-2.099 tagged_above=-999 required=5 tests=[AWL=0.150, BAYES_00=-2.599, HELO_EQ_DE=0.35]
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 e7ly-8Cdj1GP for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 11:04:14 -0700 (PDT)
Received: from mout.web.de (mout.web.de [212.227.17.12]) by ietfa.amsl.com (Postfix) with ESMTP id A30DC21E8054 for <json@ietf.org>; Thu, 6 Jun 2013 11:04:13 -0700 (PDT)
Received: from newyork.local.box ([77.13.209.10]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0LnS3i-1UAlp12Q18-00hqkv; Thu, 06 Jun 2013 20:04:09 +0200
Message-ID: <51B0CF18.1060108@drees.name>
Date: Thu, 06 Jun 2013 20:04:08 +0200
From: Stefan Drees <stefan@drees.name>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version: 1.0
To: Paul Hoffman <paul.hoffman@vpnc.org>
References: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org>
In-Reply-To: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org>
Content-Type: text/plain; charset="ISO-8859-1"; format="flowed"
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:jGD7H3QhoVZrvGyGQdA+XEKZkxiuAzQsjXTHF2/8rfu 7x4agHIS92/rX3oBSAqu4XVjOxPjOWw1my+AZ0ztLc5APSH4Hu uXaAVjKFHG0qx0vnWH1EhYJPwMpVktHwSSftPYs1Z+FNhh/yEV WLcoylez4svFakkwvrQkQePEPsl3jKQpzF+imADIxdysUgMoiL sifL+ejb+OI8hVnpkS0TQ==
Cc: "json@ietf.org" <json@ietf.org>
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
Reply-To: stefan@drees.name
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 18:04:19 -0000

On 06.06.13 19:41, Paul Hoffman 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}
>
> --Paul Hoffman
>
> ==============================
>
> And I'll start with Python.
>
> from __future__ import print_function
> import json
> a = '{"a":1,"a":2}'
> print(json.loads(a))
>
> # python2.6 keytest.py
> {u'a': 2}
> # python2.7 keytest.py
> {u'a': 2}
> # python3.2 keytest.py
> {'a': 2}
>

and also ruby(1.8.7) and the JSON parser as implemented in the json gem:

$> cat test_json.rb
require 'rubygems'
require 'json'
require 'pp'
pp JSON.parse('{"a":1,"a":2}')

$> ruby ./test_json.rb
{"a"=>2}

All the best,
Stefan.