Open akhodadadi opened 6 years ago
@akhodadadi just came up on this. This is what worked for me.
def get_nested_value(d, key):
"""Return a dictionary item given a dictionary `d` and a flattened key from `get_column_names`.
Example:
d = {
'a': {
'b': 2,
'c': 3,
},
}
key = 'a.b'
will return: 2
"""
if '.' not in key:
if key not in d:
return None
return d[key]
base_key, sub_key = key.split('.', 1)
if base_key not in d:
return None
sub_dict = d[base_key]
if sub_dict is None:
return None
return get_nested_value(sub_dict, sub_key)
I know nothing about python so Thank You.
For the file business.json, there are records (for example the 4th record) where for example the key
hours
exists but its value is None. This causes an exception in the functionget_nested_value
.To fix it, I suggest to add the following to that function before the last line (return get_nested_value(sub_dict, sub_key)):
if sub_dict is None: return None