A backend dev once sent me a 50MB CSV export from their legacy system and asked me to "just turn it into the API format." The CSV was flat—172 columns per row—but the required JSON needed nested objects with arrays. Here's what I learned about converting flat CSV to structured JSON without writing a custom parser for every file.
CSV has no concept of nesting. Every row is flat. But real data isn't flat. A customer can have multiple orders. An order can have multiple line items. The hack—the one I've seen in too many CSV exports—is to repeat the customer data in every row and rely on some prefix convention like "order_1_sku" and "order_2_sku". This works until someone adds a third order and the schema breaks.
I built Formly to handle CSV-to-JSON conversion entirely in the browser. You paste your CSV, configure how you want arrays and nested objects detected, and get structured JSON out. No server, no upload. It detects repeating column patterns automatically—if it sees "item_1", "item_2", "item_3", it knows those should collapse into an array. This has saved me hours compared to writing Node.js transform scripts for one-off conversions.
If you're comfortable on the command line, jq combined with csvjson (from csvkit) handles most transformations in a few lines. The real trick is the grouping logic—deciding which columns form the parent object and which aggregate into nested arrays. Once you've defined that, the rest is mechanical.