Skip to content

BUG: json_normalize generates TypeError: 'NoneType' object is not subscriptable as metadata object is not always present. #37783

Closed
@sann05

Description

@sann05

The example below always generate an error TypeError: 'NoneType' object is not subscriptable as metadata object is not always present.

file = [{'values': ['1', '2'], 'metadata': {'name': 'first_value'}},
        {'values': ['3', '4'], 'metadata': None}]

df = json_normalize(file,
                    record_path='values',
                    meta=[['metadata', 'name']],
                    errors='ignore')

The metadata object is dynamic and nested, so I am concerned why it doesn't generate something like this:

0 metadata.name
1 first_value
2 first_value
3 nan
4 nan

as I set errors='ignore'

@WillAyd Could you please explain the best way to handle this?

Originally posted by @sann05 in #21830 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO JSONread_json, to_json, json_normalize

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions