How to format a JSON string as a table using jq?
<p>Just started out with Bash scripting and stumbled upon jq to work with JSON.</p>
<p>I need to transform a JSON string like below to a table for output in the terminal.</p>
<pre><code>[{
    &quot;name&quot;: &quot;George&quot;,
    &quot;id&quot;: 12,
    &quot;email&quot;: &quot;george@domain.example&quot;
}, {
    &quot;name&quot;: &quot;Jack&quot;,
    &quot;id&quot;: 18,
    &quot;email&quot;: &quot;jack@domain.example&quot;
}, {
    &quot;name&quot;: &quot;Joe&quot;,
    &quot;id&quot;: 19,
    &quot;email&quot;: &quot;joe@domain.example&quot;
}]
</code></pre>
<p>What I want to display in the terminal:</p>
<pre><code>ID        Name
=================
12        George
18        Jack
19        Joe
</code></pre>
<p>Notice how I don't want to display the email property for each row, so the jq command should involve some filtering. The following gives me a plain list of names and id's:</p>
<pre><code>list=$(echo &quot;$data&quot; | jq -r '.[] | .name, .id')
printf &quot;$list&quot;
</code></pre>
<p>The problem with that is, I cannot display it like a table. I know jq has some formatting options, but not nearly as good as the options I have when using <code>printf</code>. I think I want to get these values in an array which I can then loop through myself to do the formatting...? The things I tried give me varying results, but never what I really want.</p>
<p>Can someone point me in the right direction?</p>