|
|
|
|
|
by h4l
711 days ago
|
|
Thanks for giving it a try and your feedback. I agree, the array splitting is a bit fiddly. It is actually possible to pass JSON directly, you use the :json type on the argument: $ jb dependencies:json='["Bash","Grep"]'
{"dependencies":["Bash","Grep"]}
$ jb foo=bar bar:json='"this is a well formed string"'
{"foo":"bar","bar":"this is a well formed string"}
And then you can indeed use command substitution to nest calls: $ jb foo:json=$(jb bar=baz)
{"foo":{"bar":"baz"}}
It works even better to use process substitution, this way the shell gives jb a
file path to a file to read, and so you don't need to quote the $() to avoid whitespace breaking things: $ jb foo:json@<(jb msg=$'no need\nto quote this!')
{"foo":{"msg":"no need\nto quote this!"}}
Another option is to use jb-array to generate arrays. (jb-array is best for tuple-like arrays with varying types): $ jb dependencies:json@<(jb-array Bash Grep)
{"dependencies":["Bash","Grep"]}
And if you use it from bash as a function, you can put values into a bash array and reference it: $ source json.bash
$ dependencies=(Bash Grep)
$ json @dependencies:[]
{"dependencies":["Bash","Grep"]}
|
|