Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

json to csv

const items = [
  {name: 'John', age: 31},
  {name: 'Maria', age: 25},
];

const replacer = (key, value) => value === null ? '' : value // specify how you want to handle null values here
const header = Object.keys(items[0]);
let csv = items.map(row => header.map(fieldName => row[fieldName], replacer).join(','));
csv.unshift(header.join(','));
csv = csv.join('
');

console.log(csv)
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #json #csv
ADD COMMENT
Topic
Name
1+3 =