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: 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: References: 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 To: Jabba Laci Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQmQxwNcLF83f2xEjPSzjgB2Y9pfEt7gGTB9CBGIIdFKJajC2qI/PhTdQP6WUe1Yg7DZ8xHK Cc: Python mailing list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, May 29, 2013 at 4:16 AM, Jabba Laci 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