If you want to easily process CSV and JSON files with Python check out dataknead, my new data parsing library.

Python is a lovely language for data processing, but it can get a little verbose when dealing with large nested dictionaries.

Let’s say you’re using some parsed JSON, for example from the Wikidata API. The structure is pretty predictable, but not at all times: some of the keys in the dictionary might not be available all the time.

Consider a structure like this:

animals = [
{
"animal" : "bunny"
},
{}
]

If you would try to directly access the animal property in a fashion like this:

for item in animals:
print item["animal"]

You would get an error like this:

bunny
Traceback (most recent call last):
KeyError: 'animal'

Because the animal key is missing in the second item in the list. You could use the handy get method:

for item in animals:
print item.get("animal", "no animal available")

The second argument to get is a default value that will be used if the key is not available:

bunny
no animal available

Excellent! However, this leads to problems when having a nested structure: