Actor picture

JSON to CSV Converter


Solution to convert big JSON files to CSV/Excel in JS. Paste URL for the JSON into the input along with the name of the dataset to store the records. The actor uses the dataset to handle the conversion of the items by pushing them to the dataset, which is then downloaded.

No credit card required

Author's avatarVaclav Rut
  • Modified
  • Users30
  • Runs419
Actor picture

JSON to CSV Converter


const Apify = require('apify');
const rp = require('request-promise')
const Promise = require('bluebird')
const ApifyClient = require('apify-client');

Apify.main(async () => {

    const input = await Apify.getValue('INPUT');
    const environmentVariables = await Apify.getEnv()

    const apifyClient = new ApifyClient({
        userId: environmentVariables.userId,
        token: environmentVariables.token
    const datasets = apifyClient.datasets;

    await, async (solve) => {

        if (! || !solve.url) throw new Error('Invalid input! Please provide combination of name and url');

        const inputData = await rp({uri: solve.url});

        const dataset = await datasets.getOrCreateDataset({
            datasetName: + environmentVariables.actRunId,

        const parsedData = JSON.parse(inputData);
        console.log("Loaded", parsedData.length, " for ",;

        while (parsedData.length) {
            console.log("Remaining records for",, " is: ", parsedData.length)
            await datasets.putItems({datasetId:,data: parsedData.splice(0, 1000)});
        console.log(," finished.")
        console.log("Download a CSV :" + + "/items?format=csv&attachment=1");
        console.log("Download a XLSX :" + + "/items?format=xlsx&attachment=1");

    }, {concurrency: 10})

    console.log("Job finished, see you next time.");

Actor expects the file on the input in this structure:

    "name":"Here is a name of the object 1.",
    "value1": 1,
    "end":"Thanks for watching!"
    "name":"Here is a name of the object 2.",
    "value1": 1,
    "end":"Thanks for watching!"