diff --git a/pandas/io/json/_normalize.py b/pandas/io/json/_normalize.py index b1e2210f9d894..7e3e83d59c87c 100644 --- a/pandas/io/json/_normalize.py +++ b/pandas/io/json/_normalize.py @@ -427,8 +427,8 @@ def _pull_records(js: dict[str, Any], spec: list | str) -> list: result = [] else: raise TypeError( - f"{js} has non list value {result} for path {spec}. " - "Must be list or null." + f"Path must contain list or null, " + f"but got {type(result).__name__} at {repr(spec)}" ) return result diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index 7914d40ea8aaa..0f33883feba3a 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -526,8 +526,8 @@ def test_non_list_record_path_errors(self, value): test_input = {"state": "Texas", "info": parsed_value} test_path = "info" msg = ( - f"{test_input} has non list value {parsed_value} for path {test_path}. " - "Must be list or null." + f"Path must contain list or null, " + f"but got {type(parsed_value).__name__} at 'info'" ) with pytest.raises(TypeError, match=msg): json_normalize([test_input], record_path=[test_path])