I'm having trouble parsing JSON with python, and now I'm stuck.
The problem is that the entities of my JSON are not always the same. JSON is something like:
"entries":[ { "summary": "here is the sunnary", "extensions": { "coordinates":"coords", "address":"address", "name":"name" "telephone":"123123" "url":"www.blablablah" }, } ]
I can navigate through JSON, for example:
for entrie in entries: name =entrie['extensions']['name'] tel=entrie['extensions']['telephone']
The problem arises because sometimes JSON does not have all the "fields", for example, the telephone field, it is sometimes absent, therefore the script ends with a KeyError error, because the phone key is not in this entry.
So my question is: how could I run this script, leaving an empty place where the phone is missing? I tried with:
if entrie['extensions']['telephone']: tel=entrie['extensions']['telephone']
but I think this is not normal.
ppardoz
source share