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

Riccardo Bernardini <framefritti@gmail.com> Thu, 06 June 2013 18:05 UTC

Return-Path: <framefritti@gmail.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 02F7021E80A5 for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 11:05:33 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.004
X-Spam-Level:
X-Spam-Status: No, score=-0.004 tagged_above=-999 required=5 tests=[BAYES_00=-2.599, J_CHICKENPOX_75=0.6, J_CHICKENPOX_84=0.6, NO_RELAYS=-0.001, WEIRD_QUOTING=1.396]
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 Uz5cz-W1emUg for <json@ietfa.amsl.com>; Thu, 6 Jun 2013 11:05:32 -0700 (PDT)
Received: from mail-la0-x22d.google.com (mail-la0-x22d.google.com [IPv6:2a00:1450:4010:c03::22d]) by ietfa.amsl.com (Postfix) with ESMTP id 9612821E80A9 for <json@ietf.org>; Thu, 6 Jun 2013 11:05:22 -0700 (PDT)
Received: by mail-la0-f45.google.com with SMTP id fr10so2882138lab.18 for <json@ietf.org>; Thu, 06 Jun 2013 11:05:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=fjNpfmSxr5VCovk+hNcrWHlVHf36ixiZCGKq9dKVMpM=; b=xYTU3VJ+NijnjM/xGs3L+r4SjKiiEpqHNiGU/+LU1R/go3yznn6VP5PFLCmd/TA3e7 6WK6MoMVYf4Lej4DwpQlQuzW4+nPRhPHR/dMXABXdsYaRaf59SiDeavU6oQk493+TYlF tDvwOczNtCJxe70941q3e9lQEUQrMpSoI8waKSAc5W+ZfsAqMdkXMDOUeAjGFVHQzV2z 4URDqDUwGPQi6wI1aHnXPgsWRUtMxwqUIGHHJh8fmNIz6tetwXawBTsS7PdTEwxQXpKo snIZrdk6VmrRMIw2uflFfVTD6ijLQRtG09CSAAu6a6VJ9I9mWSuAVrvXFrFboEJbjQvI NlFQ==
MIME-Version: 1.0
X-Received: by 10.112.199.100 with SMTP id jj4mr394944lbc.91.1370541921465; Thu, 06 Jun 2013 11:05:21 -0700 (PDT)
Received: by 10.112.143.165 with HTTP; Thu, 6 Jun 2013 11:05:21 -0700 (PDT)
In-Reply-To: <51B0CBAF.9070809@drees.name>
References: <C79C116D-16A4-41BA-9E5A-1055E6B9C941@vpnc.org> <51B0CBAF.9070809@drees.name>
Date: Thu, 06 Jun 2013 20:05:21 +0200
Message-ID: <CABSMSPW+SkFfR5mVZXkoEWhBD44B_w94V2A_Coi8-EksxyeSoQ@mail.gmail.com>
From: Riccardo Bernardini <framefritti@gmail.com>
To: "json@ietf.org" <json@ietf.org>
Content-Type: text/plain; charset="ISO-8859-1"
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:05:33 -0000

Ada language, parser in the package GNATCOLL.JSON (used, I think, also
by the Ada Web Server)


-------- Source code -------
with GNATCOLL.JSON;
use GNATCOLL.JSON;
with Ada.Text_IO; use Ada.Text_IO;

procedure my_test is
   Parsed : constant JSON_Value := Read ("{""a"":1,""a"":2}", "");
   Val : Integer;
begin
   Val := Get (Parsed, "a");
   Put_Line ("A=" & Integer'Image (Val));
end my_test;

----  Output ----

$ ./my_test
A= 2


On Thu, Jun 6, 2013 at 7:49 PM, Stefan Drees <stefan@drees.name> wrote:
> 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}
>
>
> don't tell anyone, but I'll continue with php (5.3.25):
> $> cat test_json.php
> <?php
> $d = json_decode('{"a":1,"a":2}');
> print_r($d);
> """
>
> $> php test_json.php
> stdClass Object
> (
>     [a] => 2
> )
>
> All the best,
> Stefan.
>
> _______________________________________________
> json mailing list
> json@ietf.org
> https://www.ietf.org/mailman/listinfo/json