Import JSON data
Load a JSON API response or local JSON document into a DataFrame for analysis.
Pandas · Function
Reads JSON text, files, URLs, or file-like objects into a pandas Series or DataFrame. It also supports line-delimited and compressed JSON, with chunksize enabling batch iteration.
Pass JSON text, a path, or a file-like object to read_json. Pandas interprets the input according to orient, optionally parses line-delimited records, and returns a DataFrame or Series; chunksize enables incremental reading through a JsonReader.
pandas.read_json(path_or_buf, *, orient=None, typ='frame', dtype=None, convert_axes=None, convert_dates=True, keep_default_dates=True, precise_float=False, date_unit=None, encoding=None, encoding_errors='strict', lines=False, chunksize=None, compression='infer', nrows=None, storage_options=None, dtype_backend=<no_default>, engine='ujson')| Name | Type | Description |
|---|---|---|
path_or_buf | str, path object, or file-like object | JSON string, path-like object, URL, or file-like object containing the input. |
orient | str, optional | Expected JSON representation, such as split, records, index, columns, values, or table. |
typ | str, default 'frame' | Object type to recover: Series or DataFrame. |
dtype | bool or dict, optional | Whether to force or specify column dtypes. |
convert_dates/date_unit | bool or list-like; str, optional | Whether to parse date-like data and which date unit to use. |
lines | bool, default False | Whether each input line is an independent JSON object. |
chunksize | int, optional | Number of rows per returned chunk; enables a JsonReader. |
compression | str or dict, default 'infer' | Compression handling for the input; infer detects it from the path extension. |
nrows | int, optional | Maximum number of rows to read. |
dtype_backend | str, default pandas._libs.lib.no_default | Backend used for nullable dtypes. |
engine | str, default 'ujson' | JSON parsing engine. |
Series, DataFrame, or pandas.api.typing.JsonReader. A JsonReader is returned when chunksize is not 0 or None.
import pandas as pd
payload = '{"alice": {"score": 91}, "bob": {"score": 84}}'
df = pd.read_json(payload, orient="index")
print(df)Reads an object whose top-level keys become row labels and returns a DataFrame.
Load a JSON API response or local JSON document into a DataFrame for analysis.
Read newline-delimited event records with lines=True and process them in batches.
Read compressed JSON directly when the source path or compression option identifies its format.
read_json accepts a JSON string, path, or file-like input and converts it to a pandas object. By default, typ is frame, so tabular input normally produces a DataFrame.
Follow-up: How would you process a large newline-delimited JSON file? Use lines=True and set chunksize to obtain a JsonReader instead of loading all records at once.
orient tells pandas which JSON layout to expect, such as records, index, columns, split, values, or table. The selected layout determines how keys, indexes, and columns are reconstructed.
Follow-up: How would you read an object keyed by row labels? Choose orient="index", optionally supplying columns when the JSON values are record-like.
With lines=True, pandas reads line-delimited JSON, where each line represents a separate JSON object. With chunksize set, the function returns a JsonReader for iterative consumption.
Follow-up: What memory behavior should be expected without chunksize? The function loads the result as a Series or DataFrame rather than exposing a batch iterator.
pandas.DataFrame.to_jsonpandas.Series.to_jsonpandas.read_tablepandas.read_orc