Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
This repository was archived by the owner on May 13, 2025. It is now read-only.

'NoneType' object is not subscriptable error when yelp_academic_dataset_business.json conversion #56

@zoldaten

Description

@zoldaten

I`ve converted all datasets in yelp_dataset except yelp_academic_dataset_business.json.
It returns a error:

Traceback (most recent call last):
  File "json_to_csv_converter2.py", line 129, in <module>
    read_and_write_file(json_file, csv_file, column_names)
  File "json_to_csv_converter2.py", line 21, in read_and_write_file
    csv_file.writerow(get_row(line_contents, column_names))
  File "json_to_csv_converter2.py", line 97, in get_row
    column_name,
  File "json_to_csv_converter2.py", line 89, in get_nested_value
    return get_nested_value(sub_dict, sub_key)
  File "json_to_csv_converter2.py", line 84, in **get_nested_value**
    return d[key]
TypeError: 'NoneType' object is not subscriptable

I`ve changed in script from:

if '.' not in key:
        if key not in d:
            return None
        return d[key]

to

if '.' not in key:
        if d==None:
            return None
        elif key not in d:
            return None
        return d[key]

and problem solved. But i do not think that`s the right way...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions