Permalink
Browse files

add binary to parse json on the CLI

  • Loading branch information...
1 parent 9eb9a3c commit 64f5ccb5e67cb7a12e948c82f03ed2df2480acaf @Floby committed Mar 25, 2013
Showing with 23 additions and 0 deletions.
  1. +20 −0 bin/parse.js
  2. +3 −0 package.json
View
20 bin/parse.js
@@ -0,0 +1,20 @@
+#!/usr/bin/env node
+
+var json = require('../');
+
+
+var paths = process.argv.slice(2);
+if(!paths.length) {
+ console.error('nothing to do.');
+ process.exit(1);
+}
+
+var parser = json.createParseStream();
+paths.forEach(function(p) {
+ parser.on(p, function(value, path) {
+ console.log('%s:\t%s', path, JSON.stringify(value));
+ });
+});
+
+process.stdin.setEncoding('utf8');
+process.stdin.pipe(parser);
View
3 package.json
@@ -28,5 +28,8 @@
},
"scripts": {
"test": "nodeunit test/test-*.js"
+ },
+ "bin": {
+ "json-parse":"bin/parse.js"
}
}

0 comments on commit 64f5ccb

Please sign in to comment.