Skip to content

Instantly share code, notes, and snippets.

@CrisFavero
Last active December 29, 2015 03:39
Show Gist options
  • Save CrisFavero/7609001 to your computer and use it in GitHub Desktop.
Save CrisFavero/7609001 to your computer and use it in GitHub Desktop.
small helper script for making cloud formation JSON lines from a regular file `node convertToJSON <filename>`
"use strict";
var fs = require('fs');
var readline = require('readline');
var stream = require('stream');
if(!process.argv[2]){
console.log("usage: convertToJSON <filename>");
process.exit(1);
}
var instream = fs.createReadStream(process.argv[2]);
var outstream = new stream();
var rl = readline.createInterface(instream, outstream);
var first = true;
rl.
on('line', function(line) {
if(first)
console.log('[');
first =false;
console.log('\t"' +line.replace(/"/g, '\\"').trimRight()+'\\n",');
})
.on('close',function(){
console.log(']');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment