Jo – a shell command to create JSON (2016)
1–10 of 100 posts
Re: Jo – a shell command to create JSON (2016)
#2Re: Jo – a shell command to create JSON (2016)
#3Re: Jo – a shell command to create JSON (2016)
#4Re: Jo – a shell command to create JSON (2016)
#5Re: Jo – a shell command to create JSON (2016)
#6In the spirit of "do one thing well", I'd so rather use this to construct JSON payloads to curl requests than the curl project's own "json part" proposal[1] under consideration.
Re: Jo – a shell command to create JSON (2016)
#7Re: Jo – a shell command to create JSON (2016)
#8Paired with httpie [2] aliases [3] it produces concise APL-like syntax:
POST https://httpbin.org/post test:=j`a=b c=`e=3` l=`*1 2 3``
Which translates to: http POST https://httpbin.org/post test:="$(jo a=b c="$(jo e=3)" l="$(jo -a 1 2 3)")"
Or, in other words, sending POST with the following body: {"a":"b","c":{"e":3},"l":[1,2,3]}
[1]: https://github.com/seletskiy/dotfiles/blob/78ac45c01bdf019ae...
[2]: https://httpie.io/
[3]: https://github.com/seletskiy/dotfiles/blob/78ac45c01bdf019ae...Re: Jo – a shell command to create JSON (2016)
#9`jq` can construct JSON "safely" from shell constructs, but is rather more verbose - e.g. with the same examples:
$ jq -n --arg name Jane '{"name":$name}'
$ jq -n \
--argjson time $(date +%s) \
--arg dir $HOME \
'{"time":$time,"dir":$dir}'
$ jq -n '$ARGS.positional' --args spring summer winter
$ jq -n \
--arg name JP \
--argjson object "$(
jq -n \
--arg fruit Orange \
--argjson point "$(
jq -n \
--argjson x 10 \
--argjson y 20 \
'{"x":$x,"y":$y}' \
)" \
--argjson number 17 \
'{"fruit":$fruit,"point":$point,"number":$number}' \
)" \
--argjson sunday false \
'{"name":$name,"object":$object,"sunday":$sunday}'Re: Jo – a shell command to create JSON (2016)
#10It's written in C and is not actively developed. The latest commit, it seems, was a pull request from me back in 2018 that fixed a null-termination issue that led to memory corruption.
Because I couldn't rely on jshon being correct, I rewrote it in Haskell here:
https://github.com/dapphub/dapptools/tree/master/src/jays
This is also not developed actively but it's a single simple ~200 line Haskell program.