title: filtering jsonb columns in loopback
body: <p>I am trying to filter <code>jsonb</code> columns in my <code>loopback</code> application but unable to.</p>
  <p>Here is my model :</p>
  <pre><code>import {Entity, model, property} from '@loopback/repository';
  
  @model({
    settings: {idInjection: false, postgresql: {schema: 'public', table: 'sampletable'}}
  })
  export class SampleModel extends Entity {
    @property({
      type: 'number',
      required: true,
      hidden: true,
      scale: 0,
      id: 1,
      postgresql: {columnName: 'id', dataType: 'bigint', dataLength: null, dataPrecision: null, dataScale: 0, nullable: 'NO'},
    })
    id: number;
  
    @property({
      type: 'number',
      required: true,
      scale: 0,
      postgresql: {columnName: 'code', dataType: 'integer', dataLength: null, dataPrecision: null, dataScale: 0, nullable: 'NO'},
    })
    code: number;
  
    @property({
      type: 'string',
      postgresql: {columnName: 'guide', dataType: 'text', dataLength: null, dataPrecision: null, dataScale: null, nullable: 'YES'},
    })
    guide?: string;
  
    @property({
      type: 'Object',
      postgresql: {columnName: 'grade_data', dataType: 'jsonb', dataLength: null, dataPrecision: null, dataScale: null, nullable: 'YES'},
    })
    gradeData?: Object;
  
    // Define well-known properties here
  
    // Indexer property to allow additional data
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    [prop: string]: any;
  
    constructor(data?: Partial&lt;SampleModel&gt;) {
      super(data);
    }
  }
  
  export interface SampleModelRelations {
    // describe navigational properties here
  }
  
  export type SampleModelWithRelations = SampleModel &amp; SampleModelRelations;
  </code></pre>
  <p>Here is the table with a sample row :</p>
  <p>For example:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>code</th>
  <th>guide</th>
  <th>grade_data</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>12345</td>
  <td>Guide for 2021</td>
  <td>{&quot;en&quot;:&quot;Eng Grade&quot;,&quot;de&quot;:&quot;Ger Grade&quot;}</td>
  </tr>
  </tbody>
  </table>
  </div>
  <ol>
  <li>Can I use <code>where</code> for filtering data within <code>jsonb</code> columns? For ex : filter for code = 12345 would be</li>
  </ol>
  <pre><code>{
    &quot;where&quot;: {
      &quot;code&quot;: 4950010
    }
  }
  </code></pre>
  <p>what would be a similar filter if I want to search for <code>grade_data -&gt;&gt; 'en'</code> ?</p>
  <ol start="2">
  <li>Can I use <code>include</code> to include only certain keys within <code>jsonb</code> column data? For ex : filter to only include code would be</li>
  </ol>
  <pre><code>{
    &quot;fields&quot;: {
      &quot;code&quot;: true
    }
  }
  </code></pre>
  <p>what would be a similar filter if I want to only retrieve <code>grade_data -&gt;&gt; 'en'</code> ?</p>