title: Querying Postgres 9.6 JSONB array of objects
body: <p>I have the following table:</p>
  
  <pre><code>CREATE TABLE trip
  (
      id SERIAL PRIMARY KEY ,
      gps_data_json jsonb NOT NULL
  );
  </code></pre>
  
  <p>The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below):</p>
  
  <ul>
  <li>mode</li>
  <li>timestamp</li>
  <li>latitude</li>
  <li>longitude</li>
  </ul>
  
  <p>I'm trying to get all rows that contain a certain "mode".</p>
  
  <pre><code>SELECT * FROM trip
  where gps_data_json -&gt;&gt; 'mode' = 'WALK';
  </code></pre>
  
  <p>I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?</p>
  
  <p>Sample data:</p>
  
  <pre><code>INSERT INTO trip (gps_data_json) VALUES
    ('[
        {
          "latitude": 47.063480377197266,
          "timestamp": 1503056880725,
          "mode": "TRAIN",
          "longitude": 15.450349807739258
        },
        {
          "latitude": 47.06362533569336,
          "timestamp": 1503056882725,
          "mode": "WALK",
          "longitude": 15.450264930725098
        }
      ]');
  
  INSERT INTO trip (gps_data_json) VALUES
    ('[
        {
          "latitude": 47.063480377197266,
          "timestamp": 1503056880725,
          "mode": "BUS",
          "longitude": 15.450349807739258
        },
        {
          "latitude": 47.06362533569336,
          "timestamp": 1503056882725,
          "mode": "WALK",
          "longitude": 15.450264930725098
        }
      ]');
  </code></pre>