irrelon-json-to-csv

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i irrelon-json-to-csv

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

4.79 kB

Total Files

7

Last publish

Collaborators

  • coolbloke1324