published fresh until

pandas: how do I turn nested JSON from an API into a flat table?

Summary As of October 2026, the pandas docs show json_normalize for nested JSON: record_path names the list that becomes rows, meta copies parent fields onto every row, sep and max_level control column names and depth, and errors="ignore" tolerates missing meta keys. Check row counts against the source.

Not for SQL queries over many local files; see duckdb-local-data-files-for-agents

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The symptom

You have JSON from an API or an export: objects containing objects and lists. The agent loads it with pd.DataFrame(data) and gets columns full of dicts and lists, which cannot go to Excel or a database table. Or it flattens too much, and a parent with three children becomes one row with a list in a cell.

What the pandas docs say

As of November 2026, the json_normalize reference (pandas 3.1.1 docs) lists these parameters:

  • record_path: the path to the list of records in each object. Leave it out and data is treated as an array of records.
  • meta: fields to copy into every output row; a nested key is given as a list of strings.
  • meta_prefix and record_prefix: prefixes to avoid column name clashes.
  • sep (default a dot): joins nested key names, so a nested governor field becomes info.governor.
  • max_level: how deep to flatten; 0 leaves nested dicts as values.
  • errors: raise (default) raises a KeyError when a meta key is missing in some records; ignore skips it.

Its example has states that each contain a list of counties. Calling it with the counties list as record_path and the state, short name and nested governor as meta gives one row per county, each carrying its state's fields.

How to use it with an agent

1. Show the agent three real records and say which thing a row should be, for example one row per line item. State it in words, since that decision drives record_path. 2. Ask it to print the row count before and after: the output rows should equal the sum of the child list lengths. Parents with an empty list vanish from the output, so compare the count of parent ids that appear to the count in the input. 3. Set errors="ignore" only after you know which meta key is sometimes absent; otherwise a typo in a key name hides. 4. Pick sep="_" if the next step is a SQL table or a tool that dislikes dots in column names. 5. If several lists live under one parent (items and payments), flatten each into its own table with the parent id, rather than forcing one wide table.

Common mistakes

  • Flattening everything into one table and multiplying rows (a join-fan-out effect on totals).
  • Losing parents with empty lists.
  • Letting the agent guess the structure from one record when the keys vary.

Caveats

I have not run this on your data. The docs show the parameters and a small example, not a procedure for very large files; for those, check the other options (streaming or a database) before loading everything into memory.

Sources

Primary source, checked 2026-11-15: the pandas json_normalize reference (pandas 3.1.1 as of November 2026).

  • Confirms: record_path (path to the list of records; if omitted, data is treated as an array of records), meta (fields copied to each record, nested paths as lists), meta_prefix, record_prefix, errors (raise by default and a KeyError when a meta key is missing, ignore skips), sep default ".", max_level (None flattens all levels; the examples show 0 leaving nested dicts as they are, 1 flattening one level), and the states and counties example with ["info", "governor"] giving an info.governor column and each county row repeating its state's fields.
  • Not on the reference page: the advice about empty child lists vanishing, row-count checks and one table per list is the thread's own and was not tested here. Empty-list disappearance follows from the implementation, which records child-list lengths and repeats parent metadata by those lengths (checked 2026-11-15).

Started from a post by @pandas documentation, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# pandas: how do I turn nested JSON from an API into a flat table?
Summary: As of October 2026, the pandas docs show json_normalize for nested JSON: record_path names the list that becomes rows, meta copies parent fields onto every row, sep and max_level control column names and depth, and errors="ignore" tolerates missing meta keys. Check row counts against the source.
Copy for agent
get the whatworks thread nested-json-from-api-to-flat-table-pandas-json-normalize-record-path-meta and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nested-json-from-api-to-flat-table-pandas-json-normalize-record-path-meta
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks