Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5793242
BUG: Fix json_normalize meta validation GH#63019
nocoding03 Nov 17, 2025
210f8f8
DOC: add whatsnew entry for json_normalize fix
nocoding03 Nov 17, 2025
4365597
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 17, 2025
c1fc462
Doc: add entry in whatsnew
nocoding03 Nov 17, 2025
7be78ec
Fix indentation for test_json_normalize_meta_string_validation
nocoding03 Nov 17, 2025
cab741a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 17, 2025
ddbe74c
Update meta validation to allow lists of strings
nocoding03 Nov 17, 2025
100de6f
Modify _validate_meta to accept multiple types
nocoding03 Nov 17, 2025
c3c173a
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 18, 2025
6906eb1
Remove non-string meta tests from json_normalize
nocoding03 Nov 19, 2025
5caa61b
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 19, 2025
e2fe7b9
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 20, 2025
94c5fcf
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 21, 2025
a5d5950
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 24, 2025
d1947c9
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 26, 2025
6fea8e1
Allow None in _validate_meta parameter validation
nocoding03 Nov 26, 2025
1e484c4
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 26, 2025
8239eff
Merge branch 'main' into fix-json-normalize-validation
nocoding03 Nov 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ I/O
- Fix bug in ``on_bad_lines`` callable when returning too many fields: now emits
``ParserWarning`` and truncates extra fields regardless of ``index_col`` (:issue:`61837`)
- Bug in :func:`pandas.json_normalize` inconsistently handling non-dict items in ``data`` when ``max_level`` was set. The function will now raise a ``TypeError`` if ``data`` is a list containing non-dict items (:issue:`62829`)
- Bug in :func:`pandas.json_normalize` raising ``TypeError`` when ``meta`` contained a non-string key (e.g., ``int``) and ``record_path`` was specified, which was inconsistent with the behavior when ``record_path`` was ``None`` (:issue:`63019`)
- Bug in :meth:`.DataFrame.to_json` when ``"index"`` was a value in the :attr:`DataFrame.column` and :attr:`Index.name` was ``None``. Now, this will fail with a ``ValueError`` (:issue:`58925`)
- Bug in :meth:`.io.common.is_fsspec_url` not recognizing chained fsspec URLs (:issue:`48978`)
- Bug in :meth:`DataFrame._repr_html_` which ignored the ``"display.float_format"`` option (:issue:`59876`)
Expand Down
32 changes: 32 additions & 0 deletions pandas/io/json/_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,37 @@ def _simple_json_normalize(
return normalized_json_object


def _validate_meta(meta: str | list[str | list[str]] | None) -> None:
"""
Validate that meta parameter contains only strings or lists of strings.
Parameters
----------
meta : str or list of str or list of list of str or None
The meta parameter to validate.
Raises
------
TypeError
If meta contains elements that are not strings or lists of strings.
"""
if meta is None:
return
if isinstance(meta, str):
return
for item in meta:
if isinstance(item, list):
for subitem in item:
if not isinstance(subitem, str):
raise TypeError(
"All elements in nested meta paths must be strings. "
f"Found {type(subitem).__name__}: {subitem!r}"
)
elif not isinstance(item, str):
raise TypeError(
"All elements in 'meta' must be strings or lists of strings. "
f"Found {type(item).__name__}: {item!r}"
)


@set_module("pandas")
def json_normalize(
data: dict | list[dict] | Series,
Expand Down Expand Up @@ -437,6 +468,7 @@ def json_normalize(

Returns normalized data with columns prefixed with the given string.
"""
_validate_meta(meta)

def _pull_field(
js: dict[str, Any], spec: list | str, extract_record: bool = False
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/io/json/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,14 @@ def test_series_non_zero_index(self):
index=[1, 2, 3],
)
tm.assert_frame_equal(result, expected)

def test_json_normalize_meta_string_validation(self):
# GH 63019
data = [{"a": 1, 12: "meta_value", "nested": [{"b": 2}]}]

# Test non-string meta raises TypeError consistently
with pytest.raises(TypeError, match="must be strings"):
json_normalize(data, meta=[12])

with pytest.raises(TypeError, match="must be strings"):
json_normalize(data, record_path=["nested"], meta=[12])
Loading