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

Tatu Saloranta <tsaloranta@gmail.com> Tue, 30 July 2013 18:14 UTC

Return-Path: <tsaloranta@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 AE19211E8108 for <json@ietfa.amsl.com>; Tue, 30 Jul 2013 11:14:00 -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=[BAYES_00=-2.599, HTML_MESSAGE=0.001, 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 5WJ8XFELj+91 for <json@ietfa.amsl.com>; Tue, 30 Jul 2013 11:13:59 -0700 (PDT)
Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) by ietfa.amsl.com (Postfix) with ESMTP id 195A711E80F3 for <json@ietf.org>; Tue, 30 Jul 2013 11:13:58 -0700 (PDT)
Received: by mail-wi0-f174.google.com with SMTP id j17so4096019wiw.13 for <json@ietf.org>; Tue, 30 Jul 2013 11:13:58 -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 :cc:content-type; bh=B8OqryX8yeUsQcKCoolCAfmRZMLXmnmPAzc2EYmUkqE=; b=F2v6HUesuRPoJieAsYV6fg1jdm/IoV6LARTrIphreQDKgLfd1UWg9csc0lfgTPwk+R JBxSzyFUmaz2yDt61rFdYGUubepHRAmakL3Bk54z8BgDzc4ba9+Im535Qs78wFE5TY5i TMc/GK9HR3qzAgdKFlStnWjobB2SpXtnhfv748vGNny5sAC/oHMGDpQ9/U0sRlJnqqTm 34GYn8NHo3f5l08mObP0UA3WCanHvJuyKDOhkw4h4hN+XdfbvFd7+/II7Rg0QgIc39CN oJx987P09ci8TI51mo2QPaax11QkgsjCKAZZD31b3ndOXLNao+jMgs0iV/ENFgDGfeHT rugw==
MIME-Version: 1.0
X-Received: by 10.180.20.116 with SMTP id m20mr1786540wie.46.1375208038172; Tue, 30 Jul 2013 11:13:58 -0700 (PDT)
Received: by 10.216.233.196 with HTTP; Tue, 30 Jul 2013 11:13:58 -0700 (PDT)
In-Reply-To: <A723FC6ECC552A4D8C8249D9E07425A71416EFE8@xmb-rcd-x10.cisco.com>
References: <B4EBDF80-ED3C-4BAA-9441-AC1B46ED5D6A@jorgechamorro.com> <A723FC6ECC552A4D8C8249D9E07425A71416EFE8@xmb-rcd-x10.cisco.com>
Date: Tue, 30 Jul 2013 11:13:58 -0700
Message-ID: <CAGrxA26HpbN0juV_03iHSeZBfN36SZJaOfuKkpsuSvX-rUQpEw@mail.gmail.com>
From: Tatu Saloranta <tsaloranta@gmail.com>
To: "Joe Hildebrand (jhildebr)" <jhildebr@cisco.com>
Content-Type: multipart/alternative; boundary="bcaec53f2e319b8db404e2be92a7"
Cc: Jorge Chamorro <jorge@jorgechamorro.com>, John Cowan <cowan@mercury.ccil.org>, "json@ietf.org WG" <json@ietf.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: Tue, 30 Jul 2013 18:14:00 -0000

On Tue, Jul 30, 2013 at 7:11 AM, Joe Hildebrand (jhildebr) <
jhildebr@cisco.com> wrote:

> On 7/30/13 1:11 PM, "Jorge Chamorro" <jorge@jorgechamorro.com> wrote:
>
> >On 28/07/2013, at 05:46, John Cowan wrote:
> >> Jorge Chamorro scripsit:
> >>
> >>> Yes, but it's problematic only for the streaming parsers that emit
> >>> [key,value] pairs, not for those which emit entire objects.
> >>
> >> In what sense are they streaming parsers, then?  The whole idea of a
> >>streaming
> >> parser is that it passes along the elements of JSON objects, arrays, and
> >> perhaps even strings and numbers bit by bit to the invoking application.
> >
> >Say you've got a stream (a pipe or a network connection) and a stream of
> >json-objects arriving through it, you may very well want the parser to
> >emit entire objects instead of its parts, no?
>
> I've never seen an implementation that is both streaming and not streaming
> at the same time.  Can you say more about how you'd write the API for
> that?  Better, can you give an example of such an implementation
>

I do not know if this is what was meant, but there is an obvious ways to
combine streaming parser with object binding (and by object binding I mean
both binding to host language types as well as tree representations).
It is what many Java JSON parsers do; Jackson, Gson, and Genson at least.

Data binding component takes a streaming parser through which it can
iterate over JSON tokens. Data binder simply reads enough tokens to build
specific object indicate by the first token: if it is START_OBJECT, it will
consume up to until matching END_OBJECT. Similarly for other types (for
scalars single token is value).

But application can also iterate over tokens directly, instead of passing
it to data binder. If content is, for example, long array of objects, it
would read START_ARRAY and first START_OBJECT, then start calling data
binder.

Here's an example (not optimal, but functional) of using streaming and
data-binding modes, in complementary way

http://stackoverflow.com/questions/15688951/combining-jackson-objectmapper-and-stream-parsing

Apologies if this is obvious -- I assumed this was common knowledge but
perhaps it is not.

-+ Tatu +-