pandas.read_json(path_or_buf=None, orient=None, typ='frame', dtype=None, convert_axes=None, convert_dates=True, keep_default_dates=True, numpy=False, precise_float=False, date_unit=None, encoding=None, lines=False, chunksize=None, compression='infer')
[source]
Convert a JSON string to pandas object.
Parameters: |
|
---|---|
Returns: |
|
See also
DataFrame.to_json
Series.to_json
Specific to orient='table'
, if a DataFrame
with a literal Index
name of index
gets written with to_json()
, the subsequent read operation will incorrectly set the Index
name to None
. This is because index
is also used by DataFrame.to_json()
to denote a missing Index
name, and the subsequent read_json()
operation cannot distinguish between the two. The same limitation is encountered with a MultiIndex
and any names beginning with 'level_'
.
>>> df = pd.DataFrame([['a', 'b'], ['c', 'd']], ... index=['row 1', 'row 2'], ... columns=['col 1', 'col 2'])
Encoding/decoding a Dataframe using 'split'
formatted JSON:
>>> df.to_json(orient='split') '{"columns":["col 1","col 2"], "index":["row 1","row 2"], "data":[["a","b"],["c","d"]]}' >>> pd.read_json(_, orient='split') col 1 col 2 row 1 a b row 2 c d
Encoding/decoding a Dataframe using 'index'
formatted JSON:
>>> df.to_json(orient='index') '{"row 1":{"col 1":"a","col 2":"b"},"row 2":{"col 1":"c","col 2":"d"}}' >>> pd.read_json(_, orient='index') col 1 col 2 row 1 a b row 2 c d
Encoding/decoding a Dataframe using 'records'
formatted JSON. Note that index labels are not preserved with this encoding.
>>> df.to_json(orient='records') '[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]' >>> pd.read_json(_, orient='records') col 1 col 2 0 a b 1 c d
Encoding with Table Schema
>>> df.to_json(orient='table') '{"schema": {"fields": [{"name": "index", "type": "string"}, {"name": "col 1", "type": "string"}, {"name": "col 2", "type": "string"}], "primaryKey": "index", "pandas_version": "0.20.0"}, "data": [{"index": "row 1", "col 1": "a", "col 2": "b"}, {"index": "row 2", "col 1": "c", "col 2": "d"}]}'
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.read_json.html