Skip to content

Instantly share code, notes, and snippets.

@kkhanal18
Created March 13, 2024 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkhanal18/2dd830256db4b2f25b7b0f4da1b5de46 to your computer and use it in GitHub Desktop.
Save kkhanal18/2dd830256db4b2f25b7b0f4da1b5de46 to your computer and use it in GitHub Desktop.
json to csv
const fs = require('fs')
const Papa = require('papaparse');
async function main() {
const API = "https://www.fda.gov/about-fda/data-export/downloadable-files?_format=json&field_foia_record_type%5b%5d=3949&field_foia_record_type%5b%5d%20=3950"
const response = await fetch(API)
let data = await response.json();
csv = Papa.unparse(data)
fs.writeFile('fasdfasdf.csv',csv, err => {
if (err) {
console.error('Error writing to CSV file:', err);
return;
}
console.log('CSV file has been saved!');
});
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment