Skip to content

Instantly share code, notes, and snippets.

@saman
Last active June 11, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saman/1f68e47c6a5551d7b7f7c88c1e8ff806 to your computer and use it in GitHub Desktop.
Save saman/1f68e47c6a5551d7b7f7c88c1e8ff806 to your computer and use it in GitHub Desktop.
Convert CAMT to JSON with Node.js
/**
* Convert CAMT to JSON with Node.js.
* @example
* // return filename.json
* node camt-to-json.js filename.csv
* @author Saman Soltani <@saman>
*/
var fs = require('fs');
var path = require('path');
var filePath = process.argv[2];
var newFilePath = path.basename(filePath, path.extname(filePath)) + '.json';
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) throw err;
var result = data.split("\n").map(record => record.split(";").map(field => field.slice(1, -1)));
fs.writeFile(newFilePath, JSON.stringify(result), function (err) {
if (err) throw err;
console.log('The file (' + newFilePath + ') has been saved!');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment