PipFoxy
Developer Tools guide

How to convert JSON to CSV

Turn arrays of JSON objects into dependable tabular exports while handling columns, nested values, quoting and spreadsheet risks.

Published 5 minute read

JSON can represent nested, irregular data, while CSV represents rows and columns. Conversion is straightforward only when the source already resembles a table. A reliable workflow validates the JSON, chooses a record shape, makes column decisions explicit and checks how the destination spreadsheet or importer will interpret every value.

Begin with an array of record objects

The clearest source is a top-level JSON array in which each item is an object representing one row. Object property names become candidate columns and property values become cells. A single object can be wrapped in an array if it genuinely represents one record, but unrelated top-level properties rarely form a useful table without a deliberate transformation.

Validate syntax before mapping columns. Comments, trailing commas, single quotes and undefined are JavaScript conventions, not JSON. Then inspect several records rather than only the first: later objects may contain additional fields, missing fields or a different value type. Decide whether the union of keys or a manually selected subset should define the export.

Choose columns and their order explicitly

JSON objects are accessed by property name, but a CSV has a visible left-to-right column order. Automatic detection is convenient for exploration; a stable export should use a documented list so a newly added API field does not silently change downstream files. Put identifiers and primary labels first, then the fields people actually need.

When a record lacks a selected property, an empty cell is a common representation. That empty cell is not automatically the same as JSON null, an empty string or a property that never existed. If the distinction matters, add a status column or choose an agreed sentinel value that cannot be confused with real data. Avoid inventing zero or false as a default.

  • Check for property names that differ only by case or whitespace.
  • Keep a schema or column mapping with repeatable exports.
  • Do not infer missing values from a neighbouring row.
  • Confirm the destination accepts the selected column names.

Flatten nested objects only when the meaning stays clear

A simple nested object can be flattened into dotted names such as address.city and address.postcode. This creates useful columns when the hierarchy is shallow and property names do not already contain the separator. Record the convention because another importer may treat dots as literal characters or as a path.

Arrays and deeply nested structures do not have one lossless tabular representation. Joining an array with commas is ambiguous when an item contains a comma; serialising it as JSON preserves the value but makes spreadsheet analysis awkward; producing one row per item can duplicate parent data. Choose based on the intended use, or leave complex fields out and export them separately.

Let a CSV writer quote fields correctly

A field containing the delimiter, a quote or a line break must be quoted. Literal quotes inside a quoted field are normally doubled. Newlines inside fields are legal in common CSV conventions, which is why manually joining rows with commas and newline characters is unsafe. Use a dedicated serializer and verify its delimiter and line-ending settings.

The file extension does not define the dialect. Some locales and applications expect semicolons because commas are used as decimal separators; others prefer tabs. Choose the delimiter for the receiving system, not the source JSON. UTF-8 is a practical text encoding, but older spreadsheet software may need an import step or byte-order mark to recognise non-English characters correctly.

  • Preview names containing commas, quotes and non-ASCII characters.
  • Do not remove embedded line breaks without a content decision.
  • Open the file through the destination's import workflow when delimiter choice matters.
  • Keep line endings consistent when another system compares files byte for byte.

Protect types and spreadsheet users

CSV has no standard type metadata. Spreadsheet software may convert long identifiers to scientific notation, strip leading zeros, reinterpret dates according to locale or round large integers. If fidelity matters, import those columns explicitly as text and compare them with the JSON source. Boolean and null values also need a written convention rather than whatever a viewer happens to infer.

Cells from untrusted data that begin with =, +, - or @ may be treated as formulas by some spreadsheet applications. Escaping strategies vary and can alter the stored text, so follow the destination's security guidance and do not open untrusted exports casually. A browser conversion being local does not make the resulting CSV safe to execute as spreadsheet content.

Verify the export and understand common limitations

Compare the number of output rows with the number of source records, allowing only documented filtering. Check the first and last record, a row with missing fields, a row with nested data and fields containing quotes or line breaks. Re-importing the CSV can reveal structural errors, although a round trip cannot recreate distinctions the format discarded.

A browser tool may struggle with very large arrays because it holds source text, parsed objects and generated CSV in memory at once. For large or regulated datasets, use a streaming, access-controlled pipeline with a fixed schema and audit trail. Retain the original JSON until the receiving system confirms the import, and never assume a successful download proves the data is complete.

  • Do not convert secrets or personal data in an untrusted environment.
  • Do not expect arbitrary nested JSON to become a lossless spreadsheet.
  • Do not discard the source before validation and acceptance.
  • Document delimiters, columns, null handling and flattening for repeatable results.

Turn the explanation into a useful result.

Start with the most relevant free tool, or explore the whole category.