<story><title>JC converts the output of popular command-line tools to JSON</title><url>https://github.com/kellyjonbrazil/jc</url></story><parent_chain><item><author>Mister_Snuggles</author><text>In FreeBSD, this problem was solved with libxo[0]:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    $ ps --libxo=json | jq
    {
      &amp;quot;process-information&amp;quot;: {
        &amp;quot;process&amp;quot;: [
          {
            &amp;quot;pid&amp;quot;: &amp;quot;41389&amp;quot;,
            &amp;quot;terminal-name&amp;quot;: &amp;quot;0 &amp;quot;,
            &amp;quot;state&amp;quot;: &amp;quot;Is&amp;quot;,
            &amp;quot;cpu-time&amp;quot;: &amp;quot;0:00.01&amp;quot;,
            &amp;quot;command&amp;quot;: &amp;quot;-bash (bash)&amp;quot;
          },
    [...]

&lt;/code&gt;&lt;/pre&gt;
It&amp;#x27;s not perfect though.  ls had support, but it was removed for reasons[1].  It&amp;#x27;s not supported by all of the utilities, etc.&lt;p&gt;This seems to be a great stop-gap with parsers for a LOT of different commands, but it relies on parsing text output that&amp;#x27;s not necessarily designed to be parsed.  It would be nice if utilities coalesced around a common flag to emit structured output.&lt;p&gt;In PowerShell, structured output is the default and it seems to work very well.  This is probably too far for Unix&amp;#x2F;Linux, but a standard &amp;quot;--json&amp;quot; flag would go a long way to getting the same benefits.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;wiki.freebsd.org&amp;#x2F;LibXo&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;wiki.freebsd.org&amp;#x2F;LibXo&lt;/a&gt;&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;reviews.freebsd.org&amp;#x2F;D13959&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;reviews.freebsd.org&amp;#x2F;D13959&lt;/a&gt;</text></item></parent_chain><comment><author>ekidd</author><text>&amp;gt; &lt;i&gt;In PowerShell, structured output is the default and it seems to work very well.&lt;/i&gt;&lt;p&gt;PowerShell goes a step beyond JSON, by supporting actual mutable &lt;i&gt;objects&lt;/i&gt;. So instead of just passing through structured data, you effectively pass around opaque objects that allow you to go back to earlier pipeline stages, and invoke methods, if I understand correctly: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;learn.microsoft.com&amp;#x2F;en-us&amp;#x2F;powershell&amp;#x2F;module&amp;#x2F;microsoft.powershell.core&amp;#x2F;about&amp;#x2F;about_methods?view=powershell-7.4&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;learn.microsoft.com&amp;#x2F;en-us&amp;#x2F;powershell&amp;#x2F;module&amp;#x2F;microsof...&lt;/a&gt;.&lt;p&gt;I&amp;#x27;m rather fond of wrappers like jc and libxo, and experimental shells like &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.nushell.sh&amp;#x2F;&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.nushell.sh&amp;#x2F;&lt;/a&gt;. These still focus on passing &lt;i&gt;data&lt;/i&gt;, not objects with executable methods. On some level, I find this comfortable: Structured data still feels pretty Unix-like, if that makes sense? If I want actual objects, then it&amp;#x27;s probably time to fire up Python or Ruby.&lt;p&gt;Knowing when to switch from a shell script to a full-fledged programming language is important, even if your shell is basically awesome and has good programming features.</text></comment>
<story><title>JC converts the output of popular command-line tools to JSON</title><url>https://github.com/kellyjonbrazil/jc</url></story><parent_chain><item><author>Mister_Snuggles</author><text>In FreeBSD, this problem was solved with libxo[0]:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    $ ps --libxo=json | jq
    {
      &amp;quot;process-information&amp;quot;: {
        &amp;quot;process&amp;quot;: [
          {
            &amp;quot;pid&amp;quot;: &amp;quot;41389&amp;quot;,
            &amp;quot;terminal-name&amp;quot;: &amp;quot;0 &amp;quot;,
            &amp;quot;state&amp;quot;: &amp;quot;Is&amp;quot;,
            &amp;quot;cpu-time&amp;quot;: &amp;quot;0:00.01&amp;quot;,
            &amp;quot;command&amp;quot;: &amp;quot;-bash (bash)&amp;quot;
          },
    [...]

&lt;/code&gt;&lt;/pre&gt;
It&amp;#x27;s not perfect though.  ls had support, but it was removed for reasons[1].  It&amp;#x27;s not supported by all of the utilities, etc.&lt;p&gt;This seems to be a great stop-gap with parsers for a LOT of different commands, but it relies on parsing text output that&amp;#x27;s not necessarily designed to be parsed.  It would be nice if utilities coalesced around a common flag to emit structured output.&lt;p&gt;In PowerShell, structured output is the default and it seems to work very well.  This is probably too far for Unix&amp;#x2F;Linux, but a standard &amp;quot;--json&amp;quot; flag would go a long way to getting the same benefits.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;wiki.freebsd.org&amp;#x2F;LibXo&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;wiki.freebsd.org&amp;#x2F;LibXo&lt;/a&gt;&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;reviews.freebsd.org&amp;#x2F;D13959&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;reviews.freebsd.org&amp;#x2F;D13959&lt;/a&gt;</text></item></parent_chain><comment><author>evnp</author><text>&lt;i&gt;&amp;gt; In PowerShell, structured output is the default and it seems to work very well. This is probably too far for Unix&amp;#x2F;Linux, but a standard &amp;quot;--json&amp;quot; flag would go a long way to getting the same benefits.&lt;/i&gt;&lt;p&gt;OP has a blog post[0] which describes exactly this. `jc` is described as a tool to fill this role &amp;quot;in the meantime&amp;quot; -- my reading is that it&amp;#x27;s intended to serve as a stepping stone towards widespread `-j`&amp;#x2F;`--json` support across unix tools.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;blog.kellybrazil.com&amp;#x2F;2019&amp;#x2F;11&amp;#x2F;26&amp;#x2F;bringing-the-unix-philosophy-to-the-21st-century&amp;#x2F;&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;blog.kellybrazil.com&amp;#x2F;2019&amp;#x2F;11&amp;#x2F;26&amp;#x2F;bringing-the-unix-ph...&lt;/a&gt;</text></comment>