zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 362 forks source link

problem flatten with AsyncParser #489

Closed fauquet-ux closed 4 years ago

fauquet-ux commented 4 years ago

version 5.0.3

I know how use flatten with parser. However flatten doesnt work with AsyncParser with the same syntax..

const {AsyncParser, transforms: {flatten}} = require('json2csv')
const extract = {}
extract.get = function get () {

    return (req) => {

        const asyncParser = new AsyncParser({transforms: [flatten({objects: true, arrays: true})]})

        let csv = ''
        asyncParser.processor.
            on('data', (chunk) => csv += chunk.toString()).
            on('end', () => console.log(csv)).
            on('error', (err) => console.error(err))

        asyncParser.input.push(JSON.stringify(req.query.data))
        asyncParser.input.push(null)
    }
}

Can u help me pls ?