Skip to content

Instantly share code, notes, and snippets.

@ataube
Created January 5, 2017 16:03
Show Gist options
  • Save ataube/f417038a82fb78106811fb4a9652b0d7 to your computer and use it in GitHub Desktop.
Save ataube/f417038a82fb78106811fb4a9652b0d7 to your computer and use it in GitHub Desktop.
Transforms a Json file and write the output back
const fs = require('fs');
const es = require('event-stream');
const JSONStream = require('JSONStream');
const inStream = fs.createReadStream('tests/fixtures/claims10k.json');
const outStream = fs.createWriteStream('tests/fixtures/claims10kPatched.json');
const map = es.mapSync((d) => {
const email = `${d.debtorName.toLowerCase()}.${d.debtorLastName.toLowerCase()}@email.com`;
return Object.assign({}, d, { email });
});
inStream
.pipe(JSONStream.parse('*'))
.pipe(map)
.pipe(JSONStream.stringify())
.pipe(outStream);
// .pipe(process.stdout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment