Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
jsoneval
#!/usr/bin/env node
var stdin = process.openStdin( );
stdin.setEncoding( 'utf8' );
var chunks = '';
stdin.on( 'data', function ( chunk ) {
chunks += chunk.toString( 'utf8' );
} );
stdin.on('end', function () {
var body = JSON.parse( chunks );
eval( process.argv[ 2 ] );
} );
eg. to print the ids of all documents within a couchdb database:
curl "http://127.0.0.1:5984/somedb/_all_docs" | jsoneval.js "body.rows.forEach( function( r ){ console.info( r.id ) } );"
@wmertens

I changed it like this to pretty-print if there is no argument:

#!/usr/bin/env node
// Use like this:
// curl "http://127.0.0.1:5984/somedb/_all_docs" | jsoneval.js "body.rows.forEach( function( r ){ console.info( r.id ) } );"

var stdin = process.openStdin( );
stdin.setEncoding( 'utf8' );
var chunks = '';
stdin.on( 'data', function ( chunk ) {
    chunks += chunk.toString( 'utf8' );
} );
stdin.on('end', function () {
    var body = JSON.parse( chunks );
    if ( process.argv[ 2 ] ) {
        eval( process.argv[ 2 ] );
    } else {
        console.info( JSON.stringify(body, null, 4) );
    }
} );
@sifu
Owner

thank you! nice idea, but if i just want to pretty-print something i just pipe it through:
"python -mjson.tool"
which i aliased to pp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.