title: How to order a json column in postgres
body: <p>So I have a jsonb column with the following structure:</p>
  
  <pre><code>{
      "fields": [{
           "name": "John",
           "position": 1
      },{
           "name": "Mike",
           "position": 2
     }]
  }
  </code></pre>
  
  <p>The jsonb column is in my "person" table. I would like to select the person table, including the jsonb column, but I also want the jsonb column to be in descending order by "position", is this possible?</p>
  
  <p>So far I have this query.</p>
  
  <pre><code>SELECT
      person_id
      name
      jsonb_agg(field ORDER BY field-&gt;'fields'-&gt;0-&gt;&gt;'position' DESC)
  FROM
      person
  WHERE (
      person_id = 42
  ) GROUP BY name
  </code></pre>