detect key conflict in a JSON file
Roy Smith
roy at panix.com
Wed May 29 09:25:39 EDT 2013
In article <mailman.2347.1369826248.3114.python-list at python.org>,
Jabba Laci <jabba.laci at gmail.com> wrote:
> 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.
The real answer here is that JSON is probably not the best choice for
large files that get hand-edited. For data that you intend to hand-edit
a lot, YAML might be a better choice.
> Currently the value of the second key silently overwrites the value of
> the first.
Yeah, that's what I would expect. http://www.json.org/ is mute on the
question of what to do with duplicate keys, but I would be quite
surprised to discover any implementation which behaved differently.
> Do you know about a command line JSON validator?
All JSON implementations validate their input. You are assuming that
having duplicate keys is "invalid". I would think it falls more into
the category of "undefined behavior".
More information about the Python-list
mailing list