Reading JSON Data
A list of records is a table waiting to happen.
Records in, table out
JSON from an API is usually a list of objects, and each object is a row. DataFrame takes that shape directly.
import pandas as pd, json
raw = '[{"name": "Ada", "score": 92}, {"name": "Grace", "score": 88}]'
df = pd.DataFrame(json.loads(raw))
print(list(df.columns))
print(df.shape)
Missing keys become missing values
A record without a key does not break the table. That column simply has a gap on that row, which is the honest result.
import pandas as pd
rows = [{"name": "Ada", "score": 92}, {"name": "Alan"}]
df = pd.DataFrame(rows)
print(df["score"].isna().sum())
Exercise
Try It YourselfWrite from_records(rows) that turns a list of dictionaries into a table and returns its column names, sorted.
Press Run to see output