ConvertersLesson 26Free preview
JSON to CSV
This lesson is part of Web Developer Tools · All levels
Summary
The JSON to CSV converter converts an array of objects into a table with a row of data and a column named after the key. The first line usually contains a header, whereas each object becomes a single line. Values containing commas, quotes, or new lines must be wrapped in quotes in order for CSV to remain valid. The nested object needs to be leveled or converted to text first because CSV only supports flat structures.
Key points
- The ideal input is an array of objects with a consistent key
- The CSV header is taken from the name of the key and written on the first line
- Fields containing commas, quotes, or newlines should be quoted
- The object must be flattened or serialised
- CSV stores text so the original data type is not always up
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.