title: How to extract json array elements in postgresql
body: <p><strong>What I want to do is sum 29.0 and 34.65 and group by P_id</strong></p>
  <pre><code>Table: transaction_items
  Column name: Debits, P_id
  Column data type: text, text
  </code></pre>
  <p>Data:</p>
  <hr />
  <h2>Debits</h2>
  <pre><code>[{&quot;amount&quot;:29.0,&quot;description&quot;:&quot;Fee_Type_1&quot;}
  [{&quot;amount&quot;:&quot;34.65&quot;,&quot;description&quot;:&quot;Fee_Type_1&quot;}
  </code></pre>
  <hr />
  <h2>P_id</h2>
  <pre><code>16
  16
  </code></pre>
  <hr />
  <p>I tried using the solution mentioned here [https://stackoverflow.com/questions/27834482/how-to-get-elements-from-json-array-in-postgresql][1]</p>
  <pre><code>select     transaction_line_items.P_id,
             each_attribute -&gt;&gt; 'amount' Rev
  from       transaction_line_items
  cross join json_array_elements(to_json(Debits)) each_section
  cross join json_array_elements(each_section -&gt; 'attributes') each_attribute
  where      (each_attribute -&gt; 'amount') is not null;
  </code></pre>
  <p>However, I got an error saying &quot;cannot deconstruct a scalar&quot;.</p>
  <p>Can someone please let me know how to parse the values I am looking for?</p>
  <p>Thank you.</p>