How to use the json2csv.Parser function in json2csv

To help you get started, we’ve selected a few json2csv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexieyizhe / intern.plus / server / migration / convertToCSV.js View on Github external
file: reviewJsonFile,
  },
};

// review, company, or job
const typeArg = process.argv[2];

if (!["-c", "-j", "-r"].includes(typeArg)) {
  console.log(
    "One of '-c', '-j', or '-r' must be specified to indicate which file type to convert!"
  );
  process.exit(1);
}

const dictEntry = dict[typeArg];
const json2csvParser = new Parser({ fields: dictEntry.fields });
const jsonInput = dictEntry.file;

console.log("Parsing...");
const csvOutput = json2csvParser.parse(jsonInput);

console.log(`Outputting to ./migration/${dictEntry.key}.csv`);
fs.writeFileSync(`./migration/${dictEntry.key}.csv`, csvOutput, () => {});

console.log("Done migration!");
github nteract / semiotic / src / components / DownloadButton.tsx View on Github external
import * as React from "react"
import { Parser } from "json2csv"

const json2csv = new Parser()

export const downloadCSV = (csvName: string, data: any) => {
  const CSV = json2csv.parse(data)
  const blob = new Blob([CSV], { type: "text/csv" })

  const dlink = document.createElement("a")
  dlink.download = csvName ? `${csvName.replace(/ /g, "_")}.csv` : "vis.csv"
  dlink.href = window.URL.createObjectURL(blob)
  dlink.onclick = () => {
    // revokeObjectURL needs a delay to work properly
    const revokeFn = () => {
      window.URL.revokeObjectURL(dlink.href)
    }
    setTimeout(revokeFn, 1500)
  }
github harishanchu / workplace / util / utilities.js View on Github external
parseJsonToCsv: (data, fields) => {
    const opts = {fields};
    let csv = '';

    try {
      const parser = new Json2csvParser(opts);
      csv = parser.parse(data);
    } catch (err) {
      console.error(err);
    }

    return csv;
  },
github miniature-tiger / block.ops / postprocessing.js View on Github external
function dataExport(localData, localFileName, fields) {
    console.log('--------- Exporting Data : ' + localFileName + '---------')
    let json2csvParser = new Json2csvParser({fields});
    let csvExport = json2csvParser.parse(localData);
    fs.writeFile(localFileName + '.csv', csvExport, function (error) {
        if (error) throw error;
    });
    return;
}
github ayakashi-io / ayakashi / src / coreScripts / saveToCSV.ts View on Github external
const dataFolder = pathJoin(system.projectFolder, "data", system.startDate);
    await mkdirp(dataFolder);
    const file = pathJoin(dataFolder, params.file || "data.csv");

    const csvConfig = {
        header: true,
        flatten: true
    };

    if (!await exists(file)) {
        await writeFile(file, "");
    } else {
        csvConfig.header = false;
    }

    const parser = new Parser(csvConfig);
    const csv = parser.parse(extraction);

    const fd = await open(file, "a");
    const ap = Buffer.from(`${csv}${EOL}`);
    await write(fd, ap, 0, ap.length);
    await close(fd);

    return input;
}
github drawrowfly / instagram-scraper / lib / instaTouch.js View on Github external
await this.zipIt();
                    }

                    let json = this._filepath ? `${this._filepath}/${this._filename}_${this._date}.json` : `${this._filename}_${this._date}.json`;
                    let csv = this._filepath ? `${this._filepath}/${this._filename}_${this._date}.csv` : `${this._filename}_${this._date}.csv`;
                    let zip = this._filepath ? `${this._filepath}/${this._filename}_${this._date}.zip` : `${this._filename}_${this._date}.zip`;

                    if (this._filetype === 'csv' || this._filetype === 'all'){
                        switch(this._scrapeType){
                            case 'user':
                            case 'hashtag':
                            case 'location':
                                this._json2csvParser = new Json2csvParser({ fields: CONST.csvFields });
                                break;
                            case 'comments':
                                this._json2csvParser = new Json2csvParser({ fields: CONST.csvCommentFields });
                                break;
                            case 'likers':
                            case 'followers':
                                this._json2csvParser = new Json2csvParser({ fields: CONST.csvLikersFields });
                                break;
                        }
                    }

                    switch(this._filetype){
                        case 'json':
                            await Bluebird.fromCallback(cb => fs.writeFile(json, JSON.stringify(this._collector), cb));
                            break;
                        case 'csv':
                            await Bluebird.fromCallback(cb => fs.writeFile(csv, this._json2csvParser.parse(this._collector), cb));
                            break;
                        case 'all':
github shirshak55 / scrapper-tools / src / jsonToCsv.ts View on Github external
return await lock.acquire('jsonToCSV', async () => {
    const parser = new Parser({
      fields,
    })
    return parser.parse(jsObjects)
  })
}
github alexbosworth / ln-service / accounting / harmonize.js View on Github external
}

  const harmonyRecords = records.map(n => ({
    'Amount': n.amount,
    'Asset': n.asset,
    'Date & Time': n.created_at,
    'Fiat Amount': n.fiat_amount,
    'From ID': n.from_id,
    'Network ID': n.external_id,
    'Notes': n.notes,
    'To ID': n.to_id,
    'Transaction ID': n.id,
    'Type': n.type,
  }));

  const parser = new Parser({fields});

  return {csv: parser.parse(harmonyRecords)};
};
github Microservice-API-Patterns / LakesideMutual / risk-management-server / lib / report-generator.js View on Github external
createCSV(fields, data) {
    const parser = new Json2csvParser({
      fields,
      delimiter: ';',
      excelStrings: true,
    })
    return parser.parse(data)
  }

json2csv

Convert JSON to CSV

MIT
Latest version published 2 years ago

Package Health Score

76 / 100
Full package analysis