Live data from Hacker News

Jo – a shell command to create JSON (2016)

jpmens.net

1–10 of 100 posts

Re: Jo – a shell command to create JSON (2016)

#5
Looks neat, but the documentation was hard to follow. A lot of typos, and some things didn't make sense. For example, I think 2 paragraphs were swapped because the example code below the paragraph taking about using square brackets has no square brackets (but nested objects) while the paragraph right after talks about nested objects but it's example doesn't show it (it does however seemingly demonstrate the square bracket feature mentioned previously)

Re: Jo – a shell command to create JSON (2016)

#8
Some time ago I wrote zsh helper [1] that uses jo to quickly construct complex JSON requests, mainly for testing and quering services from console.

Paired 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
I like it, very concise but retains all the features you need.

`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)

#10
There's also jshon which is a simple stack-based DSL for constructing JSON from shell scripts.

http://kmkeen.com/jshon/

It'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.

Post reply on HN