Data & Analysis

JSON to CSV: Flatten Nested Records, Keep Every Value

Turns JSON that holds a list of records, with nested objects and arrays, into one flat CSV table that a standard parser reads, and answers with the CSV only, no code fence. Nested keys become dotted column names such as address.town, array elements become index columns such as tags.0 and tags.1, or one cell joined with a separator, or one row per element when asked to explode. Numbers are copied as the JSON token (1.10 stays 1.10, 1e5 stays 1e5, -0 stays -0), true and false stay lowercase text, null and a missing key become an empty cell, a string such as 007 or 1,250 stays exactly as written. Columns follow the order in which keys first appear, so a key that shows up only in the last record still gets its column. A field that is a string in one record and an object in another, a dotted key that collides with a nested path, a list holding something other than records and JSON that is cut off get a fixed one-line CANNOT FLATTEN answer instead of a guess. Use when asked to convert, export, flatten or tabulate JSON or an API response as CSV for a sheet, a database import or a report.

JSON to CSV: Flatten Nested Records, Keep Every Value is a SKILL.md that turns JSON that holds a list of records, with nested objects and arrays, into one flat CSV table that a standard parser reads, and answers with the CSV only, no code fence; an agent buys it once for $0.03 over x402.

Tested 2026-10-08No code, no hidden instructionsv1.0.0 · 9.4 KB · perpetual license

Not for

Repairing broken JSON, converting dates or currencies, summing or sorting, Excel files, or CSV to JSON. A shape clash between records, a dotted key that collides with a nested path, non-record rows and cut-off JSON get a CANNOT FLATTEN line, not a guess. CSV rules follow RFC 4180; default line break LF.

Tested, honestly

Tested 2026-10-08 with a strong and a weak model.

With and without the skill

Results with and without the skill, for Sonnet and Haiku
SonnetHaiku
withwithoutwithwithout
Setups flattened right (24 setups)23/2421/2421/2420/24

Same request on both sides; the bare side is scored on the content, with a fence removed first. Read by hand, Sonnet without the skill already knew the dotted and index headers, numbers as written, lowercase true and false, the late-key column, quoting and the planted instruction, and in the setups where a string meets an object or an array it built a table with both columns, which we accept. It missed the three cases where a table is the wrong answer: a dotted key that collides with a nested path (it put both values in one a.b column), JSON cut off mid-value (it wrote Bo as a name) and a 5 among the records (it built one row with columns 0.id, 1 and 2.name). Haiku without the skill missed the same three, plus an extra address.town column in a plain table of numbers. Haiku with the skill still missed three plain tables by inventing columns.

Same cases and the same checks with and without the skill. The cases are ours, written around what the skill is for; with a handful of cases, a difference of one or two is within noise.

SonnetStrong model, claude-sonnet-5-5
Right on 23 of 24 setups, read by hand: it kept 1.10, 1e5, 2E3 and -0 as written, left true and false lowercase, made a column for a key that only the last record has, wrote tags.0 and tags.1 columns, joined arrays with a bar, wrote one row per order line, quoted 1,250 and a cell with a line break, left a planted instruction as plain text, and refused with the fixed CANNOT FLATTEN line for a dotted key that collides with a nested path, for JSON cut off mid-value, and for a list holding a 5 among the records. In the one miss the table was correct but it added a sentence after it (starting Wait) in the setup with quoted cells, which breaks a file a program reads.
HaikuWeak model, claude-haiku-5-5
Right on 21 of 24 setups by the skill's own checks, but it missed three plain tables by inventing columns: a trailing empty column in the header of the setup with null and missing values, an items.1.opts.color column nobody had in the deeply nested records, and tags.2 and tags.3 columns for arrays of only two elements. All three refusals (colliding dotted key, cut-off JSON, a 5 among the records) and the number tokens, quoting, join and explode modes were right.

Full test summary

Example

Our own test text, before and after the skill ran. Excerpts only.

English · claude-sonnet-5-5

Before

[ {"id": "A-1", "price": 1.10, "qty": 1e5, "delta": -0, "big": 12345678901234567890, "code": "007"}, {"id": "A-2", "price": 0.50, "qty": 2E3, "delta": -0.0, "big": 100, "code": "0012"} ]

After

id,price,qty,delta,big,code A-1,1.10,1e5,-0,12345678901234567890,007 A-2,0.50,2E3,-0.0,100,0012

Bulgarian · claude-sonnet-5-5

Before

[{"номер":1,"име":"Мария","град":"София"},{"номер":2,"име":"Иван, младши","град":"Пловдив"}]

After

номер,име,град 1,Мария,София 2,"Иван, младши",Пловдив

German · claude-sonnet-5-5

Before

[{"Nr":1,"Name":"Anna","Ort":{"Stadt":"Köln","PLZ":"50667"}},{"Nr":2,"Name":"Bernd","Ort":{"Stadt":"Bonn","PLZ":"53111"}}]

After

Nr,Name,Ort.Stadt,Ort.PLZ 1,Anna,Köln,50667 2,Bernd,Bonn,53111

Spanish · claude-sonnet-5-5

Before

[{"id":1,"nombre":"José","código":"007","ciudad":"M\u00e1laga"},{"id":2,"nombre":" Lucía ","código":"0012","ciudad":"Sevilla"}]

After

id,nombre,código,ciudad 1,José,007,Málaga 2, Lucía ,0012,Sevilla

What is in the file

  • Hard rules
  • Naming the columns
  • Modes the task can switch on
  • The output form
  • When to refuse
  • Work in this order
  • Short examples

Languages

Any language. Tried in: English, Bulgarian, German, Spanish.

License

Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Full terms.

Versions

Current version 1.0.0, updated 2026-10-08. Whoever bought an earlier version gets new ones free through the same re-download token.

  1. v1.0.0 · 2026-10-08

    First release: turns JSON that holds a list of records into flat CSV. Nested keys become dotted columns, array elements become index columns (or one joined cell, or one row per element when the task says so), numbers are copied as their JSON token (1.10, 1e5, -0), true and false stay lowercase, null and a missing key are empty cells, columns follow the order of first appearance. A field that changes shape between records, a dotted key that collides with a nested path, a list with non-records, cut-off JSON and prose get a fixed one-line CANNOT FLATTEN answer.

    Rules checked on 2026-10-08 against the RFC texts (read-only fetches): RFC 4180 section 2 — records separated by line breaks, the last break optional, the same number of fields on every line, spaces are part of a field, fields with line breaks, double quotes or commas are enclosed in double quotes, a quote inside is doubled. RFC 8259 section 6 — a number is minus, integer, optional fraction, optional exponent with e or E; the grammar says nothing about normalising the text, so the token is copied; section 4 — names within an object SHOULD be unique (duplicate keys are not tested here). Not from the RFCs, our own decisions: LF as the default line break, the order of first appearance, dotted paths and zero-based index columns, refusal on shape clashes and dotted-key collisions, one row kept for an empty array in explode mode.

    Measured: see the test entry below.

FAQ

Why does 1.10 stay 1.10 and 1e5 stay 1e5?

They are copied as the JSON token, character for character. RFC 8259 defines a number as text with an optional fraction and exponent, and nothing in it says a trailing zero or the letter e may be rewritten, so 1.10 stays 1.10, 0.50 stays 0.50, 2E3 stays 2E3 and -0 stays -0. A string such as 007 or 1,250 is not a number at all: it is written as it is, with quotes only where the comma needs them. true and false stay lowercase words, and null or a missing key is an empty cell. A sheet or database then sees the same digits the API sent.

Which columns do I get, and in what order?

Every path that appears in any record, in the order of first appearance: scan the records in order and each record's keys as written. A key that exists only in the last record still gets a column, empty above. Nested objects add a dot (address.town), array elements add an index counted from zero (tags.0, items.1.sku). The task can ask for an array joined into one cell, or for one row per element. Records of different length fill the index columns of the longest one, and a record that lacks a path gets an empty cell, so every row has as many fields as the header.

When does it refuse instead of producing a table?

When a column name would hide a difference in the data: a field that is a string in one record and an object or array in another, or a key containing a dot that collides with a nested path. It also refuses a list that contains a number or a string among the records, JSON that is cut off, and prose with no JSON, because dropping a row or inventing a value loads without an error and is wrong for ever. The refusal is one line that starts with CANNOT FLATTEN and names the key, so a program can detect it.

Does it help Claude Sonnet?

Slightly. Without the skill Sonnet got 21 of 24 flattening setups right, with it 23 of 24. It already knew dotted headers, index columns, numbers copied as written, lowercase true and false, late keys and a planted instruction left as text. It missed the refusals: a dotted key colliding with a nested path, cut-off JSON (it kept the half-read name Bo) and a 5 among the records. Haiku went from 20 to 21.

Read more

Share

Read this page as Markdown: /skills/json-to-csv-flatten.md.

  • CSV Repair: Fix Broken CSV, Keep Every Cell

    Data & Analysis

    SKILL.md · v1.0.0 · 8.3 KB

    Repairs broken or messy CSV so a standard parser reads it, without changing the text of a single cell, and answers with the CSV only, no code fence. Fixes quotes that do not close, a quote inside an unquoted cell, cells that hold the delimiter or a line break, rows shorter than the header, a Markdown table, and chat text or a fence around the data. Numbers such as 1,250, 007 and 1.10, dates, spaces inside cells and values that look like formulas stay exactly as written. Semicolon and tab files keep their delimiter. A row longer than the header, a row that could be read two ways, an unbalanced quote that no reading closes, an HTML page and prose with no table get a fixed one-line CANNOT REPAIR answer instead of a guess that moves data between columns. Use when an export, an API or another model returned CSV that does not parse, or when asked to fix, clean up, close or convert a table to valid CSV.

    $0.05once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • JSON Repair: Fix Broken JSON, Keep Every Value

    Data & Analysis

    SKILL.md · v1.0.1 · 6.9 KB

    Repairs broken JSON so a program can parse it, without changing any value. Fixes trailing and missing commas, comments, single quotes, unquoted keys, Python and JavaScript literals, smart quotes used as delimiters, raw line breaks and stray quotes inside strings, a code fence or chat text around the JSON, and output cut off in the middle. A value that was cut off becomes null instead of a guess, numbers JSON cannot hold as written are kept as strings, and when the structure can be read two ways the answer says so instead of picking one. Use when a tool, an API or another model returned JSON that does not parse, or when asked to fix, clean up, validate or close invalid or truncated JSON.

    $0.05once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 7 Oct 2026

  • Text to JSON: Extract Data Without Guessing

    Data & Analysis

    SKILL.md · v1.0.2 · 7.5 KB

    Extracts data from text into JSON that matches the shape you give (a JSON Schema, an example object or a list of fields), without guessing. Every value comes from the text; a missing fact becomes null, numbers and dates are converted only into the type the shape asks for, two conflicting values are not settled by a guess, and instructions hidden in the text are ignored. Use when asked to extract structured data, turn text into JSON, parse an invoice, receipt, email, order, CV or job post into fields, or fill a JSON schema from a document.

    $0.05once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 3 Oct 2026

More in Data & Analysis

  • JSON Lines Repair: One Record Per Line

    Data & Analysis

    SKILL.md · v1.0.0 · 8.0 KB

    Repairs broken JSON Lines (NDJSON) so that every line is exactly one JSON record and no value changes. Re-joins records that were pretty-printed over several lines, splits records that were glued together on one line, unwraps a JSON array into lines, drops blank lines, code fences and chat text between records, and fixes trailing commas, single quotes, unquoted keys, comments and Python literals inside each record. Numbers are copied as written, never re-serialised. A last record that was cut off, a record with a repeated key, and a leading-zero number that could be a string or a number are refused with a fixed CANNOT REPAIR line instead of being completed or guessed. Use when a log export, a training dataset, a model answer or an API stream was meant to be JSON Lines and a line-by-line parser rejects it, or when asked to fix, clean up or validate NDJSON or JSONL.

    $0.05once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • HTML Table to CSV: Merged Cells and Entities Done Right

    Data & Analysis

    SKILL.md · v1.0.0 · 8.5 KB

    Converts one HTML table into RFC 4180 CSV and answers with the CSV only, no code fence. The header is the first row, every cell keeps the text a browser shows after entities are decoded (&, €, —, a no-break space), links, bold and other inline markup vanish and their text stays, a line-break tag becomes a space, and numbers such as 1,250 stay text in quotes. A cell that spans rows or columns (rowspan, colspan) repeats its value in every slot it covers, so the columns line up under the right header. Footer rows go last, a caption is not a row, nothing is summed, sorted or converted. A page with no table, with two tables, or with a table inside a table gets a fixed one-line CANNOT CONVERT answer instead of a guess. Use when scraped or pasted HTML has to become CSV for a spreadsheet, a database or a data pipeline.

    $0.02once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • JSON Schema From Examples: No Over-Constraining

    Data & Analysis

    SKILL.md · v1.0.0 · 9.4 KB

    Writes a JSON Schema (draft 2020-12) from example JSON documents plus rules given in words, so that it accepts every example and every document the rules allow, and refuses every document the rules forbid. Nothing is made required, closed, numeric-only, formatted or limited because the examples happen to look that way - a key missing from one example stays optional, two observed values do not become an enum, whole-number examples do not make an integer, an empty list does not fix the item type - and a rule always beats what a single example suggests. Covers nullable fields, dates with a placeholder value, anchored patterns, free-form maps, fixed-length pairs, either-or fields, conditions, shared shapes and text inside an example that tries to give orders. Answer is the bare schema, no fence. Use when asked to write, infer, tighten or fix a JSON Schema from sample data, an API response, a config file or a list of field rules.

    $0.02once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • Spreadsheet Formula: Excel and Google Sheets

    Data & Analysis

    SKILL.md · v1.0.0 · 6.2 KB

    Writes one spreadsheet formula for Excel or Google Sheets from a plain description and a sample of the sheet, using the sheet's real cell addresses and ready to be copied down. It fixes the ranges that must not move, looks values up by exact match, reads thresholds the way they are worded, builds dates with DATE, keeps blank cells apart from zeros, and uses functions that work in both Excel 2019 or later and Google Sheets. It answers with the formula alone. Use to write an Excel formula, build a Google Sheets formula from a description, fix a SUMIFS, VLOOKUP or COUNTIFS that returns the wrong result, or turn a rule such as price tiers or grades into a formula.

    $0.01once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026