Last active
June 11, 2018 11:16
-
-
Save saman/1f68e47c6a5551d7b7f7c88c1e8ff806 to your computer and use it in GitHub Desktop.
Convert CAMT to JSON with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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