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


Groups > comp.lang.python > #46393 > unrolled thread

Re: detect key conflict in a JSON file

Started byChris Rebert <clp2@rebertia.com>
First post2013-05-29 10:10 -0700
Last post2013-05-29 10:10 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#46393 — Re: detect key conflict in a JSON file

FromChris Rebert <clp2@rebertia.com>
Date2013-05-29 10:10 -0700
SubjectRe: detect key conflict in a JSON file
Message-ID<mailman.2364.1369847430.3114.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web