diff --git a/pandas/io/json/_normalize.py b/pandas/io/json/_normalize.py index 642408b35ba24..71a0c674eebac 100644 --- a/pandas/io/json/_normalize.py +++ b/pandas/io/json/_normalize.py @@ -524,7 +524,10 @@ def _pull_records(js: dict[str, Any], spec: list | str) -> list: # TODO: handle record value which are lists, at least error # reasonably data = nested_to_record(data, sep=sep, max_level=max_level) - return DataFrame(data, index=index) + result = DataFrame(data, index=index) + if record_prefix is not None: + result = result.rename(columns=lambda x: f"{record_prefix}{x}") + return result elif not isinstance(record_path, list): record_path = [record_path] diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index cde0a7a378cff..b6212b514673f 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -380,6 +380,19 @@ def test_record_prefix(self, state_data): tm.assert_frame_equal(result, expected) + def test_record_prefix_no_record_path_series(self): + # Ensure record_prefix is applied when record_path is None for Series input + s = Series([{"k": f"{i}", "m": "q"} for i in range(3)]) + result = json_normalize(s, record_prefix="T.") + expected = DataFrame( + [ + {"T.k": "0", "T.m": "q"}, + {"T.k": "1", "T.m": "q"}, + {"T.k": "2", "T.m": "q"}, + ] + ) + tm.assert_frame_equal(result, expected) + def test_non_ascii_key(self): testjson = ( b'[{"\xc3\x9cnic\xc3\xb8de":0,"sub":{"A":1, "B":2}},'