irrelon-json-to-csv
v1.0.0
Published
Converts one or more JSON files to CSV files based on dot notation paths to data.
Downloads
4
Readme
JSON to CSV
Converts a JSON or group of JSON files to CSV files based on a field definition.
Install
npm i irrelon-json-to-csv
Usage
Create a field definition .js file. This will export (via commonjs / node.js module standard) an object describing the keys and paths to the data to export as csv.
Field Definition File (exampleFields.js)
module.exports = [{
title: 'User ID',
path: `id`
}, {
title: 'Email Address',
path: `user.auth.email`,
transform: (data) => {
return data.replace(/'/g, '');
}
}];
Given a json file with an array of objects (exampleData.json)
[{
"id": "1",
"user": {
"auth": {
"email": "'[email protected]'"
}
}
}]
Running from command line:
cd irrelon-json-to-csv
node index.js ./exampleFields.js ./exampleData.json
The output will be a CSV file (output_1.csv):
User ID,Email Address
1,[email protected]