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.
> 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.
> 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.
It's integrated into a lot of FreeBSD's command line tooling, and is very useful, when it's available.
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.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.