Reading CSV/XLS files using DIS

Hi there,
I’m looking for some example config files that can help when reading XLS/CSV data to write to Fliplet via DIS. I have JSON files working fine but it would be great if I didn’t need to parse the files into JSON first.

Thanks,
Dan

Hi Dan,

as DIS runs on Node.js, you can install and use NPM packages that helps converting CSV or XSL data to a JSON structure (which is the required input for Fliplet).

Here’s an example piece of code where the source() function essentially requires a previously installed npm package and uses it to parse a CSV file given its path to a JSON array:

agent.push({
  description: 'Pushes data from a CSV file to Fliplet',
  frequency: '* * * * *',
  source() {
    const csv = require('csvtojson');
    return csv().fromFile('./sample.csv');
  },
  primaryColumnName: 'id',
  targetDataSourceId: 123
});

The csvtojson package must be installed before running the code. To install it, run this command from an elevated command prompt (e.g. Powershell with Administrator rights on Windows or sudo prefix on Unix):

 npm i csvtojson -g

You can see full documentation for the package here: csvtojson - npm

There’s similar packages for XLS files too (e.g. convert-excel-to-json - npm) but I’d recommend sticking to CSV if possible as it’s a cleaner input and much faster to process.

That makes sense, thank you!