Skip to content

BUG: pd.json_normalize has inconsistent validation for non-string keys - accepts integers in some parameter combinations but rejects in others #63019

@nocoding03

Description

@nocoding03

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
data = [{"a": 1, 12: "meta_value", "nested": [{"b": 2}]}]
# This works - integer as meta  
pd.json_normalize(data, meta=[12])
# But this fails - integer as meta (with record_path)
pd.json_normalize(data, record_path=["nested"], meta=[12])

Issue Description

pd.json_normalize exhibits inconsistent behavior when using integer keys in the meta parameter:
meta=[12] (without record_path) - WORKS
record_path=["nested"], meta=[12] - FAILS with TypeError: sequence item 0: expected str instance, int found

Expected Behavior

This should either be consistently supported or consistently rejected.

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions