How to convert JSON to CSV
Short answer
To convert JSON to CSV, take an array of objects, use the object keys as the column headers, and write each object as a row. Nested objects and arrays need to be flattened or stringified, since CSV is a flat table.
From objects to rows
CSV is a flat table, so the natural source is a JSON array of objects. Each object becomes a row, and the union of their keys becomes the header row of columns.
[{"id":1,"name":"Ada"},{"id":2,"name":"Grace"}]
id,name
1,Ada
2,GraceNested data needs flattening
CSV has no concept of nesting. A nested object is usually flattened into dotted columns like address.city, while an array is either expanded into columns or written as a single stringified cell. Decide which fits how the data will be used.