const items = json const replacer = (key, value) => value === null ? '' : value const header = Object.keys(items[0]) const csv = [ header.join(','), // header row first ...items.map(row => header.map(fieldName => JSON.stringify(row[fieldName], replacer)).join(',')) ].join('\r\n') console.log(csv)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter