thinkhard.SI

Prompt repository Data & spreadsheets

Flatten a JSON export into a table you can open in a spreadsheet

An app or API gives you data as nested JSON, and you need it as a flat table you can filter and pivot in a spreadsheet.

Registry no.
DAT-054
Collection
Data & spreadsheets
Laid out for
GPT
Score
10 out of 10
Blanks to fill
7

Data & spreadsheetsGPT

The prompt

Score 10 of 10, Excellent

Use it when An app or API gives you data as nested JSON, and you need it as a flat table you can filter and pivot in a spreadsheet.

  • {{spreadsheet_app}}
  • {{row_unit}}
  • {{audience}}
  • {{approach}}
  • {{file_details}}
  • {{fields_needed}}
  • {{json_sample}}
Full prompt and why it works
Prompt
# Role
You turn nested JSON exports from apps and APIs into flat tables that open cleanly in a spreadsheet.

# Goal
Flatten the JSON export described below into a table for {{spreadsheet_app}}, with one row per {{row_unit}}, for {{audience}}, so they can filter, sort and pivot it without reading JSON.

# Success criteria
- Nested fields become columns named by their path, such as customer.address.city.
- Each array is handled by one stated rule: exploded into rows when its items are the row unit, joined into one cell with "; " when they are short values such as tags, or counted.
- A record that lacks a field gets an empty cell, not an error, and the column list is the union of keys across all records.
- IDs stay as text so leading zeros survive, and dates are written as YYYY-MM-DD or YYYY-MM-DD HH:MM with the time zone stated.

# Constraints
- Do not explode two arrays from the same record into rows at once, because every combination would become a row. Explode the one that matches the row unit, join or count the other, and say so.
- Do not invent fields that are not in the sample, and do not drop records. The code must print the number of records read and rows written.
- Use the approach I chose: {{approach}}.

# Output
1. A column plan: a table with the columns Column name, JSON path, Rule (direct, exploded, joined, counted, kept as JSON text), Example value from the sample.
2. The code in one code block, with file paths set at the top: a Python script using pandas.json_normalize (record_path and meta for an exploded array), Power Query M (Json.Document, then expanding records and lists), or an Apps Script function, whichever I chose.
3. Sample output: the first 3 to 5 rows the code would produce from my sample, as a table, taken only from the sample.
4. Fields not flattened: anything kept as raw JSON text or left out, such as arrays of arrays or fields whose type changes between records, with the reason.
5. How to run it, in up to five lines.

# Stop rules
If the sample is not valid JSON, say so. If it looks like JSON Lines (one object per line) or is cut off partway, say which and adapt the code. If it is unclear what one row should represent, ask before writing the code.

# Context
How I get the file, how big it is, and how often: {{file_details}}
Fields I need, if not all: {{fields_needed}}

A sample of the export, with personal data masked:
"""
{{json_sample}}
"""

Variables

{{spreadsheet_app}}
For example "Excel" or "Google Sheets".
{{row_unit}}
What one row should be, for example "order", "order line" or "ticket".
{{audience}}
Who will use the table, for example "the operations analysts".
{{approach}}
"a Python script", "Power Query in Excel" or "Apps Script in Google Sheets".
{{file_details}}
For example "one 40 MB file downloaded from the admin panel each Monday".
{{fields_needed}}
The fields you care about, or "all".
{{json_sample}}
Two to five complete records from the export, with personal data masked.

Why it works

  • What to avoid. Two arrays are never exploded together, which is the usual way a flattened export ends up with many more rows than records.
  • Format. A column plan maps every column to its JSON path and rule before any code, so you can see what the table will hold.
  • If unsure. Invalid or truncated JSON, JSON Lines and an unclear row unit are reported and handled instead of producing a broken table.

How to use it

  1. Press Fill in blanks and type your details into each blank. What you type stays in this browser.
  2. Copy the filled prompt into the AI tool you already use, such as ChatGPT, Claude or Gemini, or open it in the Grader or the Prompt Tester here.
  3. Before you rely on it, try it on three or four real examples. The Prompt Tester runs them all at once and shows which ones go wrong.
Use it from code

Get this prompt as JSON from the free REST API, with your own text in the blanks, or let an AI assistant fetch it through the MCP server. No key.

curl -s https://thinkhard.si/api/v1/prompts/json-export-to-table

With the MCP server added to Claude, ChatGPT, Cursor or VS Code, call get_prompt with {"prompt": "json-export-to-table"}, or just ask for it by name.