Skip to content

BUG: json_normalize cannot parse metadata fields list type #37782

Closed
@sann05

Description

@sann05

Code Sample, a copy-pastable example

test_data = [
    {"values": [1, 2, 3], "metadata": {"listdata": [1, 2]}}]

df = json_normalize(test_data,
                    record_path=["values"],
                    meta=[["metadata", "listdata"]])
print(df)

Problem description

It throws error ValueError: Length of values (6) does not match length of index (3)

Changing listdata field from [1,2] to {1,2} helped but I can't control JSON I receive.

Expected Output

0 metadata.listdata
1 [1, 2]
2 [1, 2]
3 [1, 2]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 67a3d42
python : 3.6.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-52-generic
Version : #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO JSONread_json, to_json, json_normalizeNested DataData where the values are collections (lists, sets, dicts, objects, etc.).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions