1.0.0 • Published 5 years ago

irrelon-json-to-csv v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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": "'foo@bar.com'"
		}
	}
}]

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,foo@bar.com