3 Ways to Read JSON into a pandas DataFrame

0views
C
CelesteAI
Description
Every REST API, every webhook, every BigQuery export hands you JSON. The shape varies — sometimes a records array, sometimes one-object-per-line, sometimes deeply nested — but the destination is always a DataFrame. Pandas reads all three shapes in a single line. No manual parsing, no for-loop over keys, no flattening helper. The wire format changes; the call stays simple. Source code: https://github.com/GoCelesteAI/read-json-into-dataframe This tutorial covers the three patterns every Python data person should know — all with pandas. The pd.read_json one-liner — the canonical records-shaped read, the default REST response. The lines equals True keyword — the same call, switched into JSON Lines mode for NDJSON, log pipelines, and BigQuery exports. And pd.json_normalize — the function that flattens nested API responses into dot-path columns ready for filtering and groupby. What You'll Build: - read_json.py — read three real-world JSON shapes into three DataFrames. A records array of 420 price rows, the same data as JSON Lines, and eight nested trade objects flattened with json_normalize. - The pd.read_json idiom — pass the path to a records-shaped file. Returns a DataFrame. Works on the default REST shape that every API uses. - The lines equals True keyword — one parameter switches read_json into JSON Lines mode. Same call, same DataFrame, different wire format. The format every log pipeline and streaming export already uses. - The pd.json_normalize call — flattens nested objects into flat dot-path columns. execution.price, execution.size, execution.venue. Ready for filtering, groupby, and joins. No manual recursion, no helper function. - The records vs JSON Lines distinction — when each format shows up and why pandas reads both. Records is what most APIs return. JSON Lines is what BigQuery, Snowflake, and most log shippers emit. - The dot-path column convention — json_normalize's flattening uses a dot to join nested keys. This is the same convention used by every JSON path library, every API doc, every flattening tool. Predictable, consistent, machine-readable. Timestamps: 0:00 - Intro — JSON to DataFrame in one line 0:22 - Preview — three shapes, one library 1:07 - Open read_json.py in nvim 1:30 - Method 1 — pd.read_json reads a records array 1:48 - Method 2 — lines=True reads JSON Lines 2:24 - Method 3 — json_normalize flattens nested objects 3:02 - Save and run 3:13 - Three reads, three DataFrames 3:48 - End screen — recap Key Takeaways: 1. pd.read_json is the canonical JSON-to-DataFrame in Python. Pass a records-shaped file — a list of dicts — and get a DataFrame straight out. One line, no loop, no manual parse. This is what every REST endpoint returns. 2. The lines equals True keyword reads JSON Lines / NDJSON. One object per line, no enclosing array, no commas between. Common in log pipelines, BigQuery exports, Snowflake unloads, and any streaming-friendly format. Same call, same DataFrame. 3. pd.json_normalize flattens nested objects into dot-path columns. The nested structure becomes execution.price, execution.size, execution.venue. Ready for filtering and groupby. No recursion, no helper, no manual key-walk. 4. Records vs JSON Lines is a wire-format choice, not a data choice. The records array uses brackets and commas; JSON Lines uses newlines. The DataFrame you get is identical. Pick records for human-readability, lines for streamability. 5. JSON is not your final layer. Read once, work in DataFrame. JSON is great for transport. It is not great for joins, aggregations, rolling windows, or large data. The point of this tutorial is the bridge — get out of JSON, get into pandas, do the work there. This channel is run by Claude AI. Tutorials AI-produced; reviewed and published by Codegiz. Source code at codegiz.com. #Python #JSON #Pandas #DataAnalytics #REST #DataEngineering #PythonTutorial #LearnPython #DataFrame #json_normalize --- Generated by Claude AI · part of the Common Questions in Python series
Back to tutorials

Duration

Added to Codegiz

May 22, 2026

📖 Read the articleOpen in YouTube