Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4643D10B63 for ; Thu, 20 Feb 2014 09:37:35 +0000 (UTC) Received: (qmail 2336 invoked by uid 500); 20 Feb 2014 09:37:34 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 1706 invoked by uid 500); 20 Feb 2014 09:37:33 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 1698 invoked by uid 99); 20 Feb 2014 09:37:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 09:37:32 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of dch@jsonified.com designates 209.85.215.181 as permitted sender) Received: from [209.85.215.181] (HELO mail-ea0-f181.google.com) (209.85.215.181) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 09:37:27 +0000 Received: by mail-ea0-f181.google.com with SMTP id k10so776064eaj.12 for ; Thu, 20 Feb 2014 01:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jsonified.com; s=google; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :content-type:content-transfer-encoding:content-disposition; bh=Gs7xt0MoPpluSXajpJu7PYI5aaa7i6WTJKc1JPXHoIA=; b=guoJERXK0knogntoGWBjekP9th7YkD04HitBdaCOe/P6UJQljkmhjF/NGO6zeVCzUr lgODlnkW/rIucoNhoIGxGAJqNFXgmpE8LvAYxqpEVf9Yk5J+QgVsY1wgyr2O06OPGf4K dMDPEujx95ZX/mNEH4PT55anKck5WUPx6aqvg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:message-id:in-reply-to:references :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=Gs7xt0MoPpluSXajpJu7PYI5aaa7i6WTJKc1JPXHoIA=; b=OSGf2BVTonKKrHSHOkY5GIBuppIGp7lhPOC3fISz28UO7azlH6V27FrePYGOy/xeP/ n/bWGDFTT9fh13Sefy4X17Omu658Mg+k2RrOt4lmFnKbJqAVJZmQ8yj2N5K8n+0EilBA m1To/dHQssmAYlwx2ffEqTFEZvt6AGVIs1afeRi6mmYimR8zpG+Mcjma04x8y8Utql7Q KO1xAUzyzvgNb/8CEd4TZW87E/hzxUt+33tKAk2NoUJh66SCTjiBtuY0iw3MkYaEUOME wbPlIQDQQc92rhSNJ2W/NY3Zz/S+aC5V/fBjA/rWOpXgyPjEaK3b8LgDfJov2F8+xhsu 6YUg== X-Gm-Message-State: ALoCoQl2Mm9/N2ZCyGL3KLG4jDGNh2JbOUQYtG8Nhpg2bUtg6V1P9/KgKnODIE4CO1hnCAUzMDUP X-Received: by 10.14.214.137 with SMTP id c9mr699910eep.111.1392889025899; Thu, 20 Feb 2014 01:37:05 -0800 (PST) Received: from akai.jsonified.com (212-17-107-66.static.inode.at. [212.17.107.66]) by mx.google.com with ESMTPSA id m1sm11558142een.7.2014.02.20.01.37.04 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 01:37:05 -0800 (PST) Date: Thu, 20 Feb 2014 10:37:01 +0100 From: Dave Cottlehuber To: user@couchdb.apache.org, CouchDB Developers Message-ID: In-Reply-To: References: Subject: Re: Duplicate fields in documents X-Mailer: Airmail (231) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Checked: Checked by ClamAV on apache.org > > On =46eb 19, 2014, at 6:07 AM, Dave Cottlehuber wrote: > > > > > TL;DR the appropriately named ECMA 404 JSON spec =5B1=5D is broken = or more > > politely, insufficiently specific. > > > On Wed, =46eb 19, 2014 at 8:30 PM, Jens Alfke wrote: > > > > This seems to fall into the category of =22things so obvious that the= people > > who wrote the spec didn't realize they had to mention them.=22 I.e. =22= You > > can't have duplicate keys.=E2=80=9D When I was in =46rance, I learned that anything not explicitly forbidden = is therefore permitted. And while in Germany, I learned that anything not explicitly permitted is forbidden :-). Luckily in New Zealand, it only ma= tters if you get caught ;-). On 20. =46ebruar 2014 at 06:14:29, Mikael S=C3=B6derstr=C3=B6m (vimpyboy=40= msn.com) wrote: > > If there are duplicate keys, it should absolutely fail. I think returning an error on receiving duplicate keys would be a sensibl= e change to CouchDB, albeit a relatively minor breaking one. See below. > > > JSON is typically based on a dictionary or hash map, and there's no= > > particular reason for that data structure to enforce uniqueness of ke= ys. > > > > I disagree. Mathematically, a dictionary/map object is a function: it= maps > > from a set of keys to a set of values, with each key mapping to exact= ly one > > value. (That's basically the definition of 'function'.) It's certainl= y > > possible to create implementations that map a key to =5Fmultiple=5F v= alues, but > > that's something different: it's a mapping from a key to a set. (=46o= r > > example, it's not from string-->int, it's now from string-->set.) The= > > JSON spec does not include this kind of mapping -- an object value in= JSON > > can be a number, but not a set of numbers. I was referring to the fact that hash tables usually have some form of co= llision detection internally, when multiple keys map to the same hash bucket. The= re are perfect hash functions & algorithms that avoid collisions, but that=E2=80= =99s getting a bit off track. And it=E2=80=99s moot point, as we all agree that duplic= ate keys are not what=C2=A0most people expect, including Crockford. > > IMHO the reasonable thing for a JSON parser to do if it encounters a > > duplicate key is to fail with a clear error. =46ailing that, the only= other > > reasonable option is to discard one or the other value (I don't have = an > > opinion which.) But keeping both is unreasonable. If somebody wants to sort this out, I=E2=80=99d suggest implementing the = fix (in C) in Paul Davis=E2=80=99 jiffy library, which has been on the list of things t= o import for a while. I added https://github.com/davisp/jiffy/issues/54 and updated https://issues.apache.org/jira/browse/COUCHDB-1294 jiffy:decode(<< =22=7B=5C=22foo=5C=22:=5C=22bar=5C=22, =5C=22foo=5C=22:=5C= =22bar=5C=22=7D=22 >>) should return an error, something like invalid=5Fjson=5Fduplicate=5Fname=5Fin=5Fobject. CC=E2=80=99d dev=40. A+ --=C2=A0 Dave Cottlehuber Sent from my PDP11