What does HackerNews think of libxo?

The libxo library allows an application to generate text, XML, JSON, and HTML output using a common set of function calls. The application decides at run time which output style should be produced.

Language: C

#2 in HTML
#5 in JSON
#1 in XML
Or make it flexible:

> libxo - A Library for Generating Text, XML, JSON, and HTML Output

* https://github.com/Juniper/libxo/

* https://wiki.freebsd.org/LibXo

Want structure? Ask for JSON or XML and parse. Otherwise it's the regular text output.

Can you trust it? Cli tool output is not exactly stable. I thought that's why libxo exists?

https://github.com/Juniper/libxo

Something like https://github.com/Juniper/libxo is probably the best bet for non-powershell, non-python like things to ever be properly parseable.
See also libxo:

> The libxo library allows an application to generate text, XML, JSON, and HTML output using a common set of function calls. The application decides at run time which output style should be produced. The application calls a function "xo_emit" to product output that is described in a format string. A "field descriptor" tells libxo what the field is and what it means.

* https://github.com/Juniper/libxo

Then add an "--output-format" option.

You're not the first person to think of that. See Juniper's libxo: https://github.com/Juniper/libxo

It's integrated into a lot of FreeBSD's command line tooling, and is very useful, when it's available.

Ah, that's interesting, thanks for sharing. Their github README does a nice job of showing how it doesn't add a lot of work: https://github.com/Juniper/libxo
Though it's pretty immature, nushell has a similar idea, with its own internal data model being streams of structured, typed data: https://www.nushell.sh/

And back to nix commands, libxo is used by a chunk of the FreeBSD base tools to offer output in JSON, amongst other things: https://github.com/Juniper/libxo

    -% ps --libxo=json,pretty
    {
      "process-information": {
        "process": [
          {
            "pid": "52455",
            "terminal-name": "5 ",
            "state": "Is",
            "cpu-time": "0:00.00",
            "command": "-sh (sh)"
          },

    -% uptime --libxo=json,pretty
    {
      "uptime-information": {
        "time-of-day": " 8:34p.m.",
        "uptime": 1730360,
        "days": 20,
Be nice to see more tools converted.
Object-oriented piping is actually somewhat problematic, because objects carry behavior, not just data. This means that everyone in the pipeline now has to agree on the semantics of that behavior - in case of PowerShell, they need to understand and talk the .NET object model, for example.

A much more lightweight approach is to exchange structured data. This can even be easily done on top of existing byte streams, just standardizing the format.

FreeBSD started adopting this approach via libxo for its base utilities: https://github.com/Juniper/libxo. I hope it spreads into Linux.