detect key conflict in a JSON file

Ervin Hegedüs airween at gmail.com
Wed May 29 10:04:00 EDT 2013


Hello,

On Wed, May 29, 2013 at 03:41:50PM +0200, Jabba Laci wrote:
> > 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.
> 
> Thanks but how would it be different with YAML? Can YAML check duplicate keys?

no, I think it can't,

I'm using yaml a few months ago, as I noticed, the last key
prevail.


> How to process (read) YAML files in Python? Can you give me some hints
> how to get started? All I need is read it in and create a dictionary
> of it.


import yaml


struct = yaml.load(file("yamlfile.yml" 'r'))



and struct will be a Python dictionary,



As I know, yaml modul is not part of standard Python library, but
most Linux systems has package, eg. Debian/Ubuntu has a
"python-yaml".



Cheers:


a.




More information about the Python-list mailing list