<story><title>Tips on adding JSON output to your CLI app</title><url>https://blog.kellybrazil.com/2021/12/03/tips-on-adding-json-output-to-your-cli-app/</url></story><parent_chain></parent_chain><comment><author>simonw</author><text>I hadn&amp;#x27;t seen jc before (by the author of this piece: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;kellyjonbrazil&amp;#x2F;jc&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;kellyjonbrazil&amp;#x2F;jc&lt;/a&gt; ) - what a great idea! It has parsers for around 80 different classic Unix utilities such that it can convert their output to JSON.&lt;p&gt;&lt;pre&gt;&lt;code&gt;    ~ % dig example.com | jc --dig | jq
    [
      {
        &amp;quot;id&amp;quot;: 61315,
        &amp;quot;opcode&amp;quot;: &amp;quot;QUERY&amp;quot;,
        &amp;quot;status&amp;quot;: &amp;quot;NOERROR&amp;quot;,
        &amp;quot;flags&amp;quot;: [
          &amp;quot;qr&amp;quot;,
          &amp;quot;rd&amp;quot;,
          &amp;quot;ra&amp;quot;
        ],
        &amp;quot;query_num&amp;quot;: 1,
        &amp;quot;answer_num&amp;quot;: 1,
        &amp;quot;authority_num&amp;quot;: 0,
        &amp;quot;additional_num&amp;quot;: 1,
        &amp;quot;opt_pseudosection&amp;quot;: {
          &amp;quot;edns&amp;quot;: {
            &amp;quot;version&amp;quot;: 0,
            &amp;quot;flags&amp;quot;: [],
            &amp;quot;udp&amp;quot;: 512
          }
        },
        &amp;quot;question&amp;quot;: {
          &amp;quot;name&amp;quot;: &amp;quot;example.com.&amp;quot;,
          &amp;quot;class&amp;quot;: &amp;quot;IN&amp;quot;,
          &amp;quot;type&amp;quot;: &amp;quot;A&amp;quot;
        },
        &amp;quot;answer&amp;quot;: [
          {
            &amp;quot;name&amp;quot;: &amp;quot;example.com.&amp;quot;,
            &amp;quot;class&amp;quot;: &amp;quot;IN&amp;quot;,
            &amp;quot;type&amp;quot;: &amp;quot;A&amp;quot;,
            &amp;quot;ttl&amp;quot;: 85586,
            &amp;quot;data&amp;quot;: &amp;quot;93.184.216.34&amp;quot;
          }
        ],
        &amp;quot;query_time&amp;quot;: 29,
        &amp;quot;server&amp;quot;: &amp;quot;10.0.0.1#53(10.0.0.1)&amp;quot;,
        &amp;quot;when&amp;quot;: &amp;quot;Sun Dec 05 15:12:08 PST 2021&amp;quot;,
        &amp;quot;rcvd&amp;quot;: 56,
        &amp;quot;when_epoch&amp;quot;: 1638745928,
        &amp;quot;when_epoch_utc&amp;quot;: null
      }
    ]&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>Tips on adding JSON output to your CLI app</title><url>https://blog.kellybrazil.com/2021/12/03/tips-on-adding-json-output-to-your-cli-app/</url></story><parent_chain></parent_chain><comment><author>b3morales</author><text>Another DON&amp;#x27;T, silently switching between JSON and human-readable depending on whether the output destination is a pipe. Just an extra hassle when I&amp;#x27;m writing my downstream command. Or could be phrased as a DO: give the user a switch to pick the output format, if you have both.</text></comment>