Read and Write JSON
read_json loads JSON text. to_json writes it, and orient chooses the layout such as records.
Example
import pandas as pd
import numpy as np
import io
text = '[{"a": 1, "b": "x"}, {"a": 2, "b": "y"}]'
df = pd.read_json(io.StringIO(text))
print(df)
print(df.to_json(orient='records'))Result
a b
0 1 x
1 2 y
[{"a":1,"b":"x"},{"a":2,"b":"y"}]Exercise
Write JSON records.
df.to_json(orient="")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.