JSONParser.parse() calls self.parse_json_dict(json_dict) which eventually tries for key, value in json_dict.items():, which can raise: AttributeError("'list' object has no attribute 'items'")
For example, if a user accidentally double-wraps OCDS releases in arrays:
{
"releases": [[
{"id": "1"}
]]
}
My preference would be something like:
from flattentool.exceptions import DataErrorWarning
# ...
class JSONParser(object):
# ...
def parse(self):
for num, json_dict in enumerate(self.root_json_list):
if json_dict is None:
# This is particularly useful for IATI XML, in order to not
# fall over on empty activity, e.g. <iati-activity/>
continue
# NEW CODE
if not isinstance(json_dict, dict):
warn(_(f"The value at index {num} is not a JSON object"), DataErrorWarning)
continue
JSONParser.parse()
callsself.parse_json_dict(json_dict)
which eventually triesfor key, value in json_dict.items():
, which can raise:AttributeError("'list' object has no attribute 'items'")
For example, if a user accidentally double-wraps OCDS
releases
in arrays:My preference would be something like:
Related: #398