title: postgresql json array query
body: <p>I tried to query my json array using the example here: <a href="https://stackoverflow.com/questions/10560394/how-do-i-query-using-fields-inside-the-new-postgresql-json-datatype/10560761#10560761">How do I query using fields inside the new PostgreSQL JSON datatype?</a></p>
  
  <p>They use the example:</p>
  
  <pre><code>SELECT *
  FROM   json_array_elements(
    '[{"name": "Toby", "occupation": "Software Engineer"},
      {"name": "Zaphod", "occupation": "Galactic President"} ]'
    ) AS elem
  WHERE elem-&gt;&gt;'name' = 'Toby';
  </code></pre>
  
  <p>But my Json array looks more like this (if using the example):</p>
  
  <pre><code>    {
      "people": [{
              "name": "Toby",
          "occupation": "Software Engineer"
      },
      {
          "name": "Zaphod",
          "occupation": "Galactic President"
      }
      ]
  }
  </code></pre>
  
  <p>But I get an error: ERROR:  cannot call json_array_elements on a non-array</p>
  
  <p>Is my Json "array" not really an array? I have to use this Json string because it's contained in a database, so I would have to tell them to fix it if it's not an array.
  Or, is there another way to query it?</p>
  
  <p>I read documentation but nothing worked, kept getting errors.</p>