title: Query from list of lists from JSON field
body: <p>I have a table in postgresql, which contains JSON list, each element of is also a list (it could be dictionary though I decided to make it list or tuple).</p>
  
  <p>Here is an example:</p>
  
  <pre><code>+---------------------------------------------------+
  | [["status", 10], ["status", 20]]                  |
  +---------------------------------------------------+
  | [["extra", 21], ["status", 15]]                   |
  +---------------------------------------------------+
  | [["value", 33]]                                   |
  +---------------------------------------------------+
  | [["extra", 21], ["status", 15], ["feature", 11]]  |
  +---------------------------------------------------+
  </code></pre>
  
  <p>I would like to find maximum status, i.g. zero-th element should be equal to "status" and get maximum value of the first element.
  So far I could not event extract the data, here is what I've tried:</p>
  
  <pre><code>SELECT value-&gt;0 FROM jsonb_array_elements((SELECT items::jsonb FROM mytable LIMIT 1));
  </code></pre>
  
  <p>With this query I can expand first row (<em>LIMIT 1</em>), remove limitation gives me an error:</p>
  
  <pre><code>ERROR:  more than one row returned by a subquery used as an expression
  </code></pre>
  
  <p>I believe you can emulate my situation with next query:</p>
  
  <pre><code>select * from json_array_elements((select * from json_array_elements(
      '[ [["status", 10], ["status", 20]], [["extra", 21], ["status", 15]], [["value", 33]], [["extra", 21], ["status", 15], ["feature", 11]] ]'
  )));
  </code></pre>
  
  <p>Could someone help me to expand/flatten values?</p>