Developer & Data

Turn JSON Records Into a Usable CSV File

Updated

An API may return records as JSON while an accounts team needs a spreadsheet. The conversion is straightforward when the document is an array of objects. The awkward part is deciding what to do with fields that differ between records.

Use JSON to CSV for that record shaped input. It builds columns from the object fields and returns a quoted CSV file.

Keep identifiers as strings

Try [{"name":"Ali","code":"001"},{"name":"Sara","code":"002"}]. The codes are strings in the JSON and remain textual CSV values. Writing 001 as a JSON number is not a valid way to preserve that identifier.

A column missing from one record becomes an empty cell. A null value also becomes an empty cell. If that distinction matters to your system, record it in a separate field before conversion. A CSV file does not retain every JSON type relationship.

Nested arrays or objects are represented as JSON text within their cells. They are not automatically expanded into separate rows or dotted columns. Keep the output structure in mind before sending it to another importer.

Spreadsheet protection changes text

Formula protection is enabled by default. A text value such as =2+2 is prefixed with an apostrophe so a spreadsheet is less likely to treat it as a formula. This deliberately changes the exported text.

For a machine importer that needs the literal value, select the raw option explicitly and avoid opening that file casually in a spreadsheet. Protection is an export choice, not a validation of the original business data.

After downloading, check the header order and a few records with commas or quotation marks. The CSV quoting preserves those characters, but the receiving program must still read the file with the correct delimiter and encoding.

Join the conversation

Your email address will not be published. Required fields are marked *

Explore Whatson tool information