title: PostgreSQL aggregate JSON recordset keys by row
body: <p>I have data stored in JSON arrays for each row in a PostgreSQL table like so:</p>
  
  <pre><code>id          data
  -------------------------------------------------
  1           [{"a": 1, "b": 2}, {"a": 3, "b":2}]
  2           [{"a": 5, "b": 8}, {"a": 9, "b":0}]
  </code></pre>
  
  <p>How can I get the sum of specific keys in the recordsets grouped by id?
  Here is an example of the desired result set:</p>
  
  <pre><code>id          a           b
  -------------------------------------------------
  1           4           4
  2           14          8
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>I should also mention that the data column is a jsonb data type.</p>