title: what's the simplest way to calculate the sum of values at the end of this jq command?
body: <p>I see that <code>jq</code> can calculate addition as simply as <code>jq 'map(.duration) | add'</code> but I've got a more complex command and I can't figure out how to perform this <code>add</code> at the end of it.</p>
  <p>I'm starting with data like this:</p>
  <pre><code>{
    &quot;object&quot;: &quot;list&quot;,
    &quot;data&quot;: [
      {
        &quot;id&quot;: &quot;in_1HW85aFGUwFHXzvl8wJbW7V7&quot;,
        &quot;object&quot;: &quot;invoice&quot;,
        &quot;account_country&quot;: &quot;US&quot;,
        &quot;customer_name&quot;: &quot;clientOne&quot;,
        &quot;date&quot;: 1601244686,
        &quot;livemode&quot;: true,
        &quot;metadata&quot;: {},
        &quot;paid&quot;: true,
        &quot;status&quot;: &quot;paid&quot;,
        &quot;total&quot;: 49500
      },
      {
        &quot;id&quot;: &quot;in_1HJlIZFGUwFHXzvlWqhegRkf&quot;,
        &quot;object&quot;: &quot;invoice&quot;,
        &quot;account_country&quot;: &quot;US&quot;,
        &quot;customer_name&quot;: &quot;clientTwo&quot;,
        &quot;date&quot;: 1598297143,
        &quot;livemode&quot;: true,
        &quot;metadata&quot;: {},
        &quot;paid&quot;: true,
        &quot;status&quot;: &quot;paid&quot;,
        &quot;total&quot;: 51000
      },
      {
        &quot;id&quot;: &quot;in_1HJkg5FGUwFHXzvlYp2uC63C&quot;,
        &quot;object&quot;: &quot;invoice&quot;,
        &quot;account_country&quot;: &quot;US&quot;,
        &quot;customer_name&quot;: &quot;clientThree&quot;,
        &quot;date&quot;: 1598294757,
        &quot;livemode&quot;: true,
        &quot;metadata&quot;: {},
        &quot;paid&quot;: true,
        &quot;status&quot;: &quot;paid&quot;,
        &quot;total&quot;: 57000
      },
      {
        &quot;id&quot;: &quot;in_1H8B0pFGUwFHXzvlU6nrOm6I&quot;,
        &quot;object&quot;: &quot;invoice&quot;,
        &quot;account_country&quot;: &quot;US&quot;,
        &quot;customer_name&quot;: &quot;clientThree&quot;,
        &quot;date&quot;: 1595536051,
        &quot;livemode&quot;: true,
        &quot;metadata&quot;: {},
        &quot;paid&quot;: true,
        &quot;status&quot;: &quot;paid&quot;,
        &quot;total&quot;: 20000
      }
    ],
    &quot;has_more&quot;: true,
    &quot;url&quot;: &quot;/v1/invoices&quot;
  }
  </code></pre>
  <p>and my <code>jq</code> command looks like:</p>
  <pre><code>cat example-data.json | 
    jq -C '[.data[] 
            | {invoice_id: .id, client: .customer_name, date: .date | strftime(&quot;%Y-%m-%d&quot;), amount: .total, status: .status}
            | .amount = &quot;$&quot; + (.amount/100|tostring)]
           | sort_by(.date)'
  </code></pre>
  <p>which nicely gives me output like:</p>
  <pre><code>[
    {
      &quot;invoice_id&quot;: &quot;in_1H8B0pFGUwFHXzvlU6nrOm6I&quot;,
      &quot;client&quot;: &quot;clientThree&quot;,
      &quot;date&quot;: &quot;2020-07-23&quot;,
      &quot;amount&quot;: &quot;$200&quot;,
      &quot;status&quot;: &quot;paid&quot;
    },
    {
      &quot;invoice_id&quot;: &quot;in_1HJlIZFGUwFHXzvlWqhegRkf&quot;,
      &quot;client&quot;: &quot;clientTwo&quot;,
      &quot;date&quot;: &quot;2020-08-24&quot;,
      &quot;amount&quot;: &quot;$510&quot;,
      &quot;status&quot;: &quot;paid&quot;
    },
    {
      &quot;invoice_id&quot;: &quot;in_1HJkg5FGUwFHXzvlYp2uC63C&quot;,
      &quot;client&quot;: &quot;clientThree&quot;,
      &quot;date&quot;: &quot;2020-08-24&quot;,
      &quot;amount&quot;: &quot;$570&quot;,
      &quot;status&quot;: &quot;paid&quot;
    },
    {
      &quot;invoice_id&quot;: &quot;in_1HW85aFGUwFHXzvl8wJbW7V7&quot;,
      &quot;client&quot;: &quot;clientOne&quot;,
      &quot;date&quot;: &quot;2020-09-27&quot;,
      &quot;amount&quot;: &quot;$495&quot;,
      &quot;status&quot;: &quot;paid&quot;
    }
  ]
  </code></pre>
  <p>and I want to add a sum/total at the end of that, something like <code>Total: $1775</code>, so that the entire output would look like this:</p>
  <pre><code>[
    {
      &quot;invoice_id&quot;: &quot;in_1H8B0pFGUwFHXzvlU6nrOm6I&quot;,
      &quot;client&quot;: &quot;clientThree&quot;,
      &quot;date&quot;: &quot;2020-07-23&quot;,
      &quot;amount&quot;: &quot;$200&quot;,
      &quot;status&quot;: &quot;paid&quot;
    },
    {
      &quot;invoice_id&quot;: &quot;in_1HJlIZFGUwFHXzvlWqhegRkf&quot;,
      &quot;client&quot;: &quot;clientTwo&quot;,
      &quot;date&quot;: &quot;2020-08-24&quot;,
      &quot;amount&quot;: &quot;$510&quot;,
      &quot;status&quot;: &quot;paid&quot;
    },
    {
      &quot;invoice_id&quot;: &quot;in_1HJkg5FGUwFHXzvlYp2uC63C&quot;,
      &quot;client&quot;: &quot;clientThree&quot;,
      &quot;date&quot;: &quot;2020-08-24&quot;,
      &quot;amount&quot;: &quot;$570&quot;,
      &quot;status&quot;: &quot;paid&quot;
    },
    {
      &quot;invoice_id&quot;: &quot;in_1HW85aFGUwFHXzvl8wJbW7V7&quot;,
      &quot;client&quot;: &quot;clientOne&quot;,
      &quot;date&quot;: &quot;2020-09-27&quot;,
      &quot;amount&quot;: &quot;$495&quot;,
      &quot;status&quot;: &quot;paid&quot;
    }
  ]
  Total: $1775
  </code></pre>
  <p>Is there a neat/tidy way to enhance this <code>jq</code> command to achieve this?<br />
  Or even, since I'm invoking this in a shell script, a dirty/ugly way with bash?</p>