Data Formats
JSON to CSV Guide: Export API Data to Spreadsheets Cleanly
Flatten JSON records into spreadsheet-friendly CSV while deciding how to handle nested objects, arrays, missing keys, commas, dates, and spreadsheet-sensitive values.
In this article
JSON to CSV Guide: Export API Data to Spreadsheets Cleanly
JSON is excellent for nested application data. CSV is excellent for rows and columns.
Converting JSON to CSV is useful when API data needs to be reviewed in Excel, Google Sheets, data-analysis tools, or simple import workflows.
Duck Cloud's JSON to CSV exports arrays of JSON objects as CSV locally in the browser.
Flat objects convert most cleanly
This JSON:
[
{
"name": "Isaac",
"email": "[email protected]",
"active": true
}
]maps naturally to columns:
name,email,activeEvery object becomes a row.
Nested objects require a decision
Consider:
{
"name": "Isaac",
"address": {
"city": "Yangon",
"country": "Myanmar"
}
}CSV has no universal nested-object structure.
Possible strategies include:
- flatten to
address.cityandaddress.country; - serialize the object as JSON inside one cell;
- exclude the nested field;
- create a separate table.
Choose based on how the spreadsheet will be used.
Arrays are also ambiguous
A field such as:
"tags": ["cloud", "security", "tools"]could become:
- one joined text cell;
- JSON text in one cell;
- multiple columns;
- a separate row per tag.
There is no single correct answer.
Document the export strategy.
Missing keys
Objects in an array may not have identical fields.
For example, one record may include phone while another does not.
A CSV export normally creates a common set of columns and leaves missing values blank.
Review whether blank means “unknown,” “not applicable,” or an empty value in your domain.
CSV quoting
Values may contain:
- commas;
- quotes;
- line breaks.
A proper CSV serializer escapes these according to CSV conventions.
Do not generate CSV by manually joining object values with commas.
Spreadsheet injection
Spreadsheet applications can interpret cells beginning with characters such as =, +, -, or @ as formulas in certain contexts.
If exported data comes from untrusted users and will be opened in spreadsheet software, investigate CSV/spreadsheet injection risks and sanitize according to your threat model.
Do not assume a data export is harmless simply because it contains text.
Large numbers and IDs
Spreadsheet software may alter:
- long IDs;
- phone numbers;
- postal codes;
- credit-like identifiers;
- numbers with leading zeros.
If exact textual preservation matters, test the actual spreadsheet import workflow.
Dates
JSON may contain ISO 8601 date strings or epoch timestamps.
For epoch data, use the Unix Timestamp Converter to inspect the intended date before deciding how an export should present it.
Store one consistent date representation in the CSV.
Validate before exporting
Start with valid JSON.
Use the JSON Validator to catch syntax errors and the JSON Viewer to inspect nested structure.
If the data is heavily nested, reconsider whether CSV is the right destination.
Export checklist
- Validate the JSON.
- Confirm the top-level shape.
- Define columns.
- Decide how nested objects are flattened.
- Decide how arrays are represented.
- Handle missing values consistently.
- Use proper CSV quoting.
- Consider spreadsheet formula risks.
- Test IDs and dates.
- Open a sample export in the target spreadsheet application.
JSON-to-CSV conversion works best when you define the table first. Flattening is a data-model decision, not merely a formatting operation.