Created
March 11, 2015 05:34
-
-
Save nichoth/3fdea252671328242adb to your computer and use it in GitHub Desktop.
Simple CLI for JSON transformation using Node.js streams
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
#!/usr/bin/env node | |
// Clean up JSON from openlibrary.org and output as NDJSON. | |
// use: | |
// curl 'http://openlibrary.org/subjects/love.json' | ./toNdjson.js | |
var JSONStream = require('JSONStream'); | |
var map = require('through2-map'); | |
var cherryPick = map.obj(function(obj) { | |
return { | |
key: obj.key, | |
title: obj.title, | |
authors: obj.authors, | |
subject: obj.subject, | |
}; | |
}); | |
process.stdin | |
.pipe(JSONStream.parse('works.*')) | |
.pipe(cherryPick) | |
.pipe(JSONStream.stringify(false)) | |
.pipe(process.stdout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment