Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46393

Re: detect key conflict in a JSON file

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'example:': 0.03; 'detect': 0.07; 'json': 0.07; 'subject:file': 0.07; 'key.': 0.09; 'cc:addr :python-list': 0.11; 'subject:key': 0.16; 'url:json': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'first.': 0.19; 'cc:addr:python.org': 0.22; 'cheers,': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'file': 0.32; 'url:python': 0.33; 'received:google.com': 0.35; 'hi,': 0.36; 'url:org': 0.36; 'growing': 0.38; 'url:library': 0.38; 'how': 0.40; 'manually': 0.60; 'happen': 0.63; 'to:addr:gmail.com': 0.65; 'repeat': 0.74; 'sender:addr:chris': 0.84; 'silently': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=VvTCaq5ReMx9DDnfUs5KVjTauUyXWc5/h6XJxFrlpgo=; b=Nz80j3xRtM6e1H5eENgqgDXQcK7fL/tUx9jJ3enlX+ZdoXS37FS6ki+yuSBPQUWzH3 L9VKhB4AojM6b88qtJfBe/wbZvFNexVp8XeuQ8ZvARm6CNuiaLSHMVQTrvnLyXNr3+qZ dbgDHoyfeyUXK13r9AFGA1vwRXZSU1zqt5Lq4=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=VvTCaq5ReMx9DDnfUs5KVjTauUyXWc5/h6XJxFrlpgo=; b=polP4jygdju08s3nu2/GBmfdrDiG5TIITQD8HCf/sezY7TH+EVgjjUKMKYMDIQ/mew G0JKCM+qtjkYY/sMPLhqPcPePTFFt3ENdTJ+u8xwiwgR9ZkSMBK7UUjE2ZU8hILf53pm 02viN+xmepRtGNNV2+h03jaErtGJxjiXB0uvSDrO0WbPH7wzdV5dMpewjhXmSA8zPWDM 8PzohYDU0AMi6cBkuu6+WfGn5tWdn8ylKTXaPA7JxHn6VRIGa8TmAKJtqZU13XbtQIjZ K+DsK/s/z6ADKaxehEEcZro6zCCORhh+knvL74zA9GkQSAu5YacKxm6VaiuuqpEHHw21 qVdg==
MIME-Version 1.0
X-Received by 10.42.70.147 with SMTP id f19mr1512223icj.30.1369847426545; Wed, 29 May 2013 10:10:26 -0700 (PDT)
Sender chris@rebertia.com
In-Reply-To <CAOuJsMn38V2Gw3s=KMLJ+t4uFyu3GdzYyA-_TNiEqn7hWxNEjA@mail.gmail.com>
References <CAOuJsMn38V2Gw3s=KMLJ+t4uFyu3GdzYyA-_TNiEqn7hWxNEjA@mail.gmail.com>
Date Wed, 29 May 2013 10:10:26 -0700
X-Google-Sender-Auth QebQVFZNvgEI5hlX4hoRJ50Exno
Subject Re: detect key conflict in a JSON file
From Chris Rebert <clp2@rebertia.com>
To Jabba Laci <jabba.laci@gmail.com>
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQmQxwNcLF83f2xEjPSzjgB2Y9pfEt7gGTB9CBGIIdFKJajC2qI/PhTdQP6WUe1Yg7DZ8xHK
Cc Python mailing list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2364.1369847430.3114.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369847430 news.xs4all.nl 15930 [2001:888:2000:d::a6]:41918
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46393

Show key headers only | View raw


On Wed, May 29, 2013 at 4:16 AM, Jabba Laci <jabba.laci@gmail.com> wrote:
> Hi,
>
> How can you detect if a key is duplicated in a JSON file? Example:
>
> {
>     "something": [...],
>     ...
>     "something": [...]
> }
>
> I have a growing JSON file that I edit manually and it might happen
> that I repeat a key. If this happens, I would like to get notified.
> Currently the value of the second key silently overwrites the value of
> the first.

You can pass an appropriate object_pairs_hook function to json.load():
http://docs.python.org/2/library/json.html#repeated-names-within-an-object
http://docs.python.org/2/library/json.html#json.load

Cheers,
Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: detect key conflict in a JSON file Chris Rebert <clp2@rebertia.com> - 2013-05-29 10:10 -0700

csiph-web