title: Querying JSONB. Sequelize Op.In throws Error: Invalid value
body: <p>I have a postgresql JSONB field named "config".</p>
  
  <p>Example of a value in the field "config"</p>
  
  <pre><code>{ 
     "rewards":{ 
        "policyA":[ 
           { 
              "enforcedDate":"some-date",
              "anotherKey":"some-val"
           },
           { 
              "enforcedDate":"some-date-2",
              "anotherKey":"some-val-2"
           }
        ]
     }
  }
  </code></pre>
  
  <p>Here's what I've tried. I am trying to find all records that has an enforcedDate of "some-date" as such.</p>
  
  <pre><code>MyEntity.findAndCountAll({
    where: {
      config: {
        rewards: {
          policyA: [ { enforcedDate: "some-date" } ]
        }
      }
    }
  });
  </code></pre>
  
  <p>Or </p>
  
  <pre><code>MyEntity.findAndCountAll({
    where: {
      config: {
        rewards: {
          policyA: {
            [Op.in]: [ { enforcedDate: "some-date" } ]
          }
        }
      }
    }
  });
  </code></pre>
  
  <p>Error I am getting</p>
  
  <pre><code>Invalid value { enforcedDate: 'some-date' }
  
        at escape (node_modules/sequelize/lib/sql-string.js:65:11)
        at Object.partialEscape [as escape] (node_modules/sequelize/lib/sql-string.js:57:37)
        at ABSTRACT.&lt;anonymous&gt; (node_modules/sequelize/lib/dialects/postgres/data-types.js:469:22)
            at Array.map (&lt;anonymous&gt;)
        at ABSTRACT._value (node_modules/sequelize/lib/dialects/postgres/data-types.js:458:19)
        at ABSTRACT._stringify (node_modules/sequelize/lib/dialects/postgres/data-types.js:473:29)
        at ABSTRACT.stringify (node_modules/sequelize/lib/data-types.js:23:19)
        at Object.escape (node_modules/sequelize/lib/sql-string.js:59:40)
        at PostgresQueryGenerator.escape (node_modules/sequelize/lib/dialects/abstract/query-generator.js:986:22)
        at PostgresQueryGenerator._whereParseSingleValueObject (node_modules/sequelize/lib/dialects/abstract/query-generator.js:2556:41)
        at PostgresQueryGenerator.whereItemQuery (node_modules/sequelize/lib/dialects/abstract/query-generator.js:2272:21)
        at PostgresQueryGenerator._traverseJSON (node_modules/sequelize/lib/dialects/abstract/query-generator.js:2392:21)
        at node_modules/sequelize/lib/dialects/abstract/query-generator.js:2385:14
        at node_modules/lodash/lodash.js:4905:15
        at baseForOwn (node_modules/lodash/lodash.js:2990:24)
        at Function.forOwn (node_modules/lodash/lodash.js:13014:24)
        at PostgresQueryGenerator._traverseJSON (node_modules/sequelize/lib/dialects/abstract/query-generator.js:2384:9)
        at node_modules/sequelize/lib/dialects/abstract/query-generator.js:2361:12
        at node_modules/lodash/lodash.js:4905:15
        at baseForOwn (node_modules/lodash/lodash.js:2990:24)
        at Function.forOwn (node_modules/lodash/lodash.js:13014:24)
        at PostgresQueryGenerator._whereJSON (node_modules/sequelize/lib/dialects/abstract/query-generator.js:2360:7)
  </code></pre>
  
  <p>Seems to be similar to <a href="https://stackoverflow.com/questions/51370932/sequelize-op-contains-throws-unhandled-rejection-error-invalid-value">Sequelize Op.contains throws Unhandled rejection Error: Invalid value</a> </p>
  
  <p>Which has no answer to it.</p>
  
  <p>Raw sql query like the 1 below works fine</p>
  
  <pre><code> select *
      FROM "MyEntity"
      where config @&gt; '{"rewards": {"policyA": [{"enforcedDate": "some-date"}]}}';
  </code></pre>