Created
January 5, 2017 16:03
-
-
Save ataube/f417038a82fb78106811fb4a9652b0d7 to your computer and use it in GitHub Desktop.
Transforms a Json file and write the output back
This file contains 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
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