title: Knexjs PgSQL json query
body: <p>I have a column in a Postgres that stores some JSON data. The JSON has no defined schema, but it should be possible to search all records that have some specified key.</p>
  
  <p>I'm using KnexJS to build the queries and so far I came up with this: </p>
  
  <pre><code>tx.select('*').from('table')
  .whereRaw('cast(data-&gt;&gt;? as ?) = ?', [key, type, JSON.parse(value)]));
  </code></pre>
  
  <p>But it's not working because I don't think it will be possible to specify the type.</p>
  
  <p>Still, when I try to specify it manually like this:</p>
  
  <pre><code>tx.select('*').from('table')
  .whereRaw('cast(data-&gt;&gt;? as boolean) = ?', [key, JSON.parse(value)]));
  </code></pre>
  
  <p>It still doesn't work! This is the log from the console when using <code>DEBUG:knex:*</code></p>
  
  <pre><code>{ key: 'admin', value: 'true', type: 'boolean' }
    knex:tx trx1: Starting top level transaction +0ms
    knex:pool INFO pool postgresql:pg:client0 - dispense() clients=1 available=0 +2ms
    knex:client acquired connection from pool: __knexUid2 +38ms
    knex:query BEGIN; +2ms
    knex:bindings undefined +1ms
    knex:query select * from "contexts" where cast(data-&gt;&gt;? as boolean) = ? +18ms
    knex:bindings [ 'admin', true ] +0ms
    knex:query COMMIT; +9ms
    knex:bindings undefined +0ms
    knex:tx trx1: releasing connection +6ms
    knex:client releasing connection to pool: __knexUid2 +1ms
    knex:pool INFO pool postgresql:pg:client0 - dispense() clients=0 available=1 +1ms
  </code></pre>
  
  <p>Any ideas on how I can accomplish this?</p>
  
  <p>thanks in advance!</p>