Created
May 31, 2015 03:17
-
-
Save vicapow/a143c8dc2de2654ead1f to your computer and use it in GitHub Desktop.
js-to-json
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/local/bin/node | |
var vm = require('vm'); | |
var Writable = require('stream').Writable; | |
var ws = Writable(); | |
var chunks = []; | |
ws._write = function (chunk, enc, next) { | |
chunks.push(chunk); | |
next(); | |
}; | |
process.stdin.on('end', function() { | |
var obj = Buffer.concat(chunks).toString(); | |
var sandbox = {obj: null}; | |
vm.runInNewContext('obj = ' + obj, sandbox); | |
console.log(JSON.stringify(sandbox.obj, null, 2)); | |
}); | |
process.stdin.pipe(ws); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment