Normalize semi-structured JSON data into a flat table. This method is designed to transform semi-structured JSON data, such as nested dictionaries or lists, into a flat table. This is particularly useful when handling JSON-like data structures that contain deeply nested fields.
(
data: dict | list[dict] | Series,
record_path: str | list | None = None,
meta: str | list[str | list[str]] | None = None,
meta_prefix: str | None = None,
record_prefix: str | None = None,
errors: IgnoreRaise = "raise",
sep: str = ".",
max_level: int | None = None,
)
| 302 | |
| 303 | @set_module("pandas") |
| 304 | def json_normalize( |
| 305 | data: dict | list[dict] | Series, |
| 306 | record_path: str | list | None = None, |
| 307 | meta: str | list[str | list[str]] | None = None, |
| 308 | meta_prefix: str | None = None, |
| 309 | record_prefix: str | None = None, |
| 310 | errors: IgnoreRaise = "raise", |
| 311 | sep: str = ".", |
| 312 | max_level: int | None = None, |
| 313 | ) -> DataFrame: |
| 314 | """ |
| 315 | Normalize semi-structured JSON data into a flat table. |
| 316 | |
| 317 | This method is designed to transform semi-structured JSON data, such as nested |
| 318 | dictionaries or lists, into a flat table. This is particularly useful when |
| 319 | handling JSON-like data structures that contain deeply nested fields. |
| 320 | |
| 321 | Parameters |
| 322 | ---------- |
| 323 | data : dict, list of dicts, or Series of dicts |
| 324 | Unserialized JSON objects. |
| 325 | record_path : str or list of str, default None |
| 326 | Path in each object to list of records. If not passed, data will be |
| 327 | assumed to be an array of records. |
| 328 | meta : list of paths (str or list of str), default None |
| 329 | Fields to use as metadata for each record in resulting table. |
| 330 | meta_prefix : str, default None |
| 331 | String to prefix records with dotted path, e.g. foo.bar.field if |
| 332 | meta is ['foo', 'bar']. |
| 333 | record_prefix : str, default None |
| 334 | String to prefix records with dotted path, e.g. foo.bar.field if |
| 335 | path to records is ['foo', 'bar']. |
| 336 | errors : {'raise', 'ignore'}, default 'raise' |
| 337 | Configures error handling. |
| 338 | |
| 339 | * 'ignore' : will ignore KeyError if keys listed in meta are not |
| 340 | always present. |
| 341 | * 'raise' : will raise KeyError if keys listed in meta are not |
| 342 | always present. |
| 343 | sep : str, default '.' |
| 344 | Nested records will generate names separated by sep. |
| 345 | e.g., for sep='.', {'foo': {'bar': 0}} -> foo.bar. |
| 346 | max_level : int, default None |
| 347 | Max number of levels(depth of dict) to normalize. |
| 348 | if None, normalizes all levels. |
| 349 | |
| 350 | Returns |
| 351 | ------- |
| 352 | DataFrame |
| 353 | The normalized data, represented as a pandas DataFrame. |
| 354 | |
| 355 | See Also |
| 356 | -------- |
| 357 | DataFrame : Two-dimensional, size-mutable, potentially heterogeneous tabular data. |
| 358 | Series : One-dimensional ndarray with axis labels (including time series). |
| 359 | |
| 360 | Examples |
| 361 | -------- |