Flattening a JSON array into rows and columns
[{"name":"Ada","role":"eng"},{"name":"Lin","role":"design"}] converts to a CSV with header row 'name,role' followed by 'Ada,eng' and 'Lin,design' -- each object in the array becomes one CSV row, with its keys becoming the header columns.
The header row is derived directly from the first object's keys, in whatever order those keys appear -- if later objects in the array have different keys than the first one, this converter's column structure follows the first object, so consistent key naming and ordering across all objects in the array is what makes the resulting CSV reliable.
This is a common and useful direction for the conversion: JSON is convenient for APIs and code, while CSV is what spreadsheet tools, simple data imports, and many analytics platforms expect -- this bridges that gap for simple, flat data structures.
Why only flat, first-level data converts cleanly
First-level keys only. Nested objects are stringified as a single cell. If any value in the JSON is itself an object or array (a nested structure), it gets stringified as a single text blob inside its CSV cell rather than being broken out into its own columns -- CSV's flat row-and-column structure has no native way to represent nested data, so something has to give.
Every object in the array should ideally share the same set of keys for a clean, consistent CSV -- objects with missing keys will produce empty cells in those columns, while objects with extra keys beyond the first object's set may have that extra data dropped from the output entirely.
Values containing commas, quotes, or line breaks need proper CSV quoting to avoid corrupting the row/column structure when the resulting CSV is opened elsewhere -- confirm the output handles those edge cases correctly if your actual data includes them.
Related conversion tools for the reverse direction
To go the other direction -- CSV data back into a JSON array -- the CSV to JSON Converter handles that.
For turning the same flat data into an HTML table for direct display instead of a CSV file, the HTML Table from CSV Generator is the related output format.
Frequently Asked Questions (FAQ)
How are the CSV column headers determined?
From the keys of the first object in the JSON array, in the order they appear in that object. Subsequent rows are filled in based on those same column names, matched to each object's corresponding key.
What happens to a nested object or array as a value?
First-level keys only. Nested objects are stringified as a single cell. It gets converted to a text representation and placed inside a single CSV cell, rather than being broken into its own separate columns -- CSV's flat structure has no native way to represent nested data.
What if some objects in the array are missing a key that others have?
Objects missing a key that appears in the header row will produce an empty cell for that column in their row, since the column structure is fixed by the first object's keys rather than dynamically adjusted per row.
Does this handle values containing commas or quotes correctly?
Values with commas, quotes, or line breaks need proper CSV quoting (wrapping the value in quotes and escaping internal quotes) to avoid corrupting the row structure -- verify this behaves correctly for your specific data if it includes those characters.
Is this the same as exporting from a spreadsheet application?
The output format is standard CSV, compatible with spreadsheet imports, but this tool only processes flat JSON array data you paste in -- it's a text conversion utility, not a spreadsheet application itself.