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.