Last active
October 12, 2015 15:28
-
-
Save iwill/4047683 to your computer and use it in GitHub Desktop.
JSON Parsing and Editing, run Javascript Function and Statements in Shell via Node.js
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
#!/bin/bash | |
# @see https://www.npmjs.org/package/json | |
## nodejs [js-statement ...] js-expression | |
function nodejs() { | |
local statements="" | |
while [[ $# > 1 ]]; do | |
statements="${statements:+$statements; }$1" | |
shift | |
done | |
node -e "${statements}; var __nodejs_result__ = $1; console.log(__nodejs_result__);" | |
} | |
export -f nodejs | |
## nodejs js-expression | |
# @see http://stackoverflow.com/questions/23500098/node-js-syntaxerror-unexpected-end-of-input | |
# nodejs() { | |
# node -e "console.log($1)" | |
# } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parse JSON
Parse JSON Object
Parse JSON Array
JS Function
Call JS Function
Edit JSON via JS Function
JS Statements
Call JS Statements + Expression
Edit JSON via JS Statements + Expression
???: Edit JSON via JS Statements + Return