What does HackerNews think of jo?

JSON output from a shell

Language: C

[I'm not recommending this, but maybe… No, no. I'm not sure…]

It isn't even just the newer shells that have solved this, zsh also has a solution out of the box¹. The extensive globbing support in zsh can largely replace `find`, and things like zargs allow you to reuse your common knowledge throughout the shell.

For example, performing your first example with zargs would use regular option separators(`--`), regular expansion(`{1..5}`), and standard shell constructs for the commands to execute.

I'll contrive up an example based around your file counter, but slightly different to show some other functionality.

    f() { fs=($1/*(.)); jo $1=$#fs }
    zargs -P 32 -n1 -- **/*(/) -- f
That should recursively list directories, counting only the files within each, and output² jsonl that can be further mangled within the shell². You could just as easily populate an associative array for further work, or $whatever. Unlike bash, zsh has reasonable behaviour around quoting and whitespace too.

Edit to add: I'm not suggesting zargs is a replacement for parallel, but if you're only using a small subset of its functionality then it may be able to replace that.

¹ https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht...

² https://github.com/jpmens/jo

³ https://github.com/stedolan/jq

I'm a big fan of jo[1] for making generating JSON from the shell not terrible.

[1] https://github.com/jpmens/jo

This. jo (https://github.com/jpmens/jo) solves what this proposal seems to be about.
It probably isn't as user friendly as you'd want, but you can reload the playlist by firing commands at a socket. See the "JSON IPC" section in the mpv man page, and specifically the load* commands. jo¹ and socat² are probably the simplest way to use it if you're not looking for heavy scripting.

The scriptability of mpv is really nice if you're the sort of person who likes building your perfect environment, and also a huge pit of addictive time sinks.

¹ https://github.com/jpmens/jo

² http://www.dest-unreach.org/socat/

There are tools like jo[1] which will encode output of shell commands into json.

As for native shell support for structured data, Powershell is probably the best implementation. In Powershell objects can be piped to other commands and they can be serialized to json, xml, csv, and even html [2]

[1] https://github.com/jpmens/jo [2] https://docs.microsoft.com/en-us/powershell/module/microsoft...

Source code on Github: https://github.com/jpmens/jo

Looks like GPL license. Cool!

I _love_ jq. It's been an incredibly useful tool for me since I discovered it ~6 months ago. However, article mentions "jq -n"; I personally find jq syntax less appealing when it comes to generating JSON instead of parsing it. For that particular task, I prefer using "jo":

https://github.com/jpmens/jo

jq & jo are the Calvin & Hobbes of the shell: lots of fun together!

A few examples:

- Generate a simple JSON object:

  $ jo foo=12 bar=true baz=null
  {"foo":12,"bar":true,"baz":"null"}
- Want a nested object?

  $ jo foo=12 bar=true baz=null thing=$(jo number=57 test=string)
  {"foo":12,"bar":true,"baz":"null","thing":{"number":57,"test":"string"}}
- What about arrays?

  $ jo thing=$(jo number=57 test=string) anarray=$(jo -a 1 2 3 4 5)
  {"thing":{"number":57,"test":"string"},"anarray":[1,2,3,4,5]}
- Now let's add some jq magic to sum all the values in the array together:

  $ jo thing=$(jo number=57 test=string) anarray=$(jo -a 1 2 3 4 5) | jq '.anarray | add'
  15
Great stuff :)