Skip to content

Conversation

@nocoding03
Copy link
Contributor

@nocoding03 nocoding03 commented Nov 17, 2025

Currently, json_normalize exhibits inconsistent behavior when using non-string keys in the meta parameter:

  • meta=[12] (without record_path) - incorrectly works
  • meta=[12] (with record_path) - correctly fails with TypeError

This inconsistency violates the principle of least surprise and contradicts the documented API.

@nocoding03 nocoding03 changed the title Fix json normalize validation Fix json normalize 'meta' validation Nov 17, 2025
@nocoding03
Copy link
Contributor Author

pre-commit.ci autofix

pre-commit-ci bot and others added 3 commits November 17, 2025 10:46
Updated the _validate_meta function to accept a string or a list of strings/lists of strings as input.
@nocoding03
Copy link
Contributor Author

@rhshadrach could you please take a look at this PR?

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! It seems to me the meta argument is not expected to be large data (e.g. hundreds of entries) and so these instance checks are okay. Also it seems questionable to me whether this should go through deprecation. I'd like another eye here - cc @mroeschke

@nocoding03 nocoding03 requested a review from mroeschke November 26, 2025 13:41
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM merge when ready @rhshadrach

@mroeschke mroeschke added the IO JSON read_json, to_json, json_normalize label Nov 26, 2025
@mroeschke mroeschke added this to the 3.0 milestone Nov 26, 2025
@rhshadrach rhshadrach added the Error Reporting Incorrect or improved errors from pandas label Nov 27, 2025
@rhshadrach rhshadrach changed the title Fix json normalize 'meta' validation BUG: Fix json normalize 'meta' validation Nov 27, 2025
@rhshadrach rhshadrach changed the title BUG: Fix json normalize 'meta' validation BUG: Fix json_normalize 'meta' validation Nov 27, 2025
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rhshadrach rhshadrach added the Bug label Nov 27, 2025
@rhshadrach rhshadrach merged commit 1b5b02c into pandas-dev:main Nov 27, 2025
51 checks passed
@rhshadrach
Copy link
Member

Thanks @nocoding03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Error Reporting Incorrect or improved errors from pandas IO JSON read_json, to_json, json_normalize

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants