Re: [Json] Call for real-world examples of how parsers deal with duplicate keys
Bjoern Hoehrmann <derhoermi@gmx.net> Thu, 06 June 2013 18:18 UTC
Return-Path: <derhoermi@gmx.net>
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 64F0F21F9424 for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 11:18:29 -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=[AWL=0.000, BAYES_00=-2.599]
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 A+83SeSQwwuq for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 11:18:25 -0700 (PDT)
Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by ietfa.amsl.com (Postfix) with ESMTP id A486721F9298 for <json@ietf.org>; Thu, 6 Jun 2013 11:18:24 -0700 (PDT)
Received: from mailout-de.gmx.net ([10.1.76.20]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0MaXUl-1V4feY1UBl-00K8kw for <json@ietf.org>; Thu, 06 Jun 2013 20:18:23 +0200
Received: (qmail invoked by alias); 06 Jun 2013 18:18:22 -0000
Received: from p5B2318C1.dip0.t-ipconnect.de (EHLO netb.Speedport_W_700V) [91.35.24.193] by mail.gmx.net (mp020) with SMTP; 06 Jun 2013 20:18:22 +0200
X-Authenticated: #723575
X-Provags-ID: V01U2FsdGVkX19HU7Z3pbdHA/KRKymeoF7gDaTr1FOnoi3b29TCA7 gUsd7VVIBmtiup
From: Bjoern Hoehrmann <derhoermi@gmx.net>
To: Paul Hoffman <paul.hoffman@vpnc.org>
Date: Thu, 06 Jun 2013 20:18:23 +0200
Message-ID: <sli1r8pmmu8c425p6ar63ehe3ka8rot339@hive.bjoern.hoehrmann.de>
References: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org>
In-Reply-To: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org>
X-Mailer: Forte Agent 3.3/32.846
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Y-GMX-Trusted: 0
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
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:18:29 -0000
* 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} I note that this test is insufficient for a conclusion like "takes the last value", but it should be okay for concluding "does not reject the input under default settings". With Perl, the JSON module on CPAN has a pure-perl module JSON::PP, but would generally prefer a a C-based module like JSON::XS when available (and `use JSON;` hides the choice). #!perl -w use JSON::PP; use Data::Dumper; print Dumper([ JSON::PP->new->decode('{"a":1,"a":2}') ]); and the same with JSON::XS in place of JSON::PP will print $VAR1 = [ { 'a' => 2 } ]; In Microsoft's .NET Framework the System.Runtime.Serialization.Json reader abstracts JSON into XML... using System; using System.Text; using System.Runtime.Serialization.Json; class Program { static void Main(string[] args) { var json = "{\"a\":1,\"a\":2}"; var bytes = UTF8Encoding.UTF8.GetBytes(json); var p = JsonReaderWriterFactory.CreateJsonReader(bytes, new System.Xml.XmlDictionaryReaderQuotas()); while (p.Read()) { Console.WriteLine("{0}", p.ReadOuterXml()); } } } which results in <root type="object"> <a type="number">1</a> <a type="number">2</a> </root> This being a streaming parser it reports both instances as they are in the document. -- Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de 25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
- [Json] Call for real-world examples of how parser… Paul Hoffman
- Re: [Json] Call for real-world examples of how pa… Stefan Drees
- Re: [Json] Call for real-world examples of how pa… Stefan Drees
- Re: [Json] Call for real-world examples of how pa… Riccardo Bernardini
- Re: [Json] Call for real-world examples of how pa… Matt Miller (mamille2)
- Re: [Json] Call for real-world examples of how pa… Bjoern Hoehrmann
- Re: [Json] Call for real-world examples of how pa… Tatu Saloranta
- Re: [Json] Call for real-world examples of how pa… Vinny A
- Re: [Json] Call for real-world examples of how pa… Stephan Beal
- Re: [Json] Call for real-world examples of how pa… Vinny A
- Re: [Json] Call for real-world examples of how pa… Nico Williams
- Re: [Json] Call for real-world examples of how pa… Nico Williams
- Re: [Json] Call for real-world examples of how pa… Tatu Saloranta
- Re: [Json] Call for real-world examples of how pa… Allen Wirfs-Brock