title: Postgres - query JSON column value of nested object
body: <p>I'm using following schema for the JSONB column of my table (named <strong>fields</strong>). There are several of these <strong>field</strong> entries.</p>
  
  <pre><code>{
     "FIELD_NAME": {
        "value" : "FIELD_VALUE",
        "meta": {
           "indexable": true
        }
     }
  }
  </code></pre>
  
  <p>I need to find all the <em>fields</em> that contain this object</p>
  
  <pre><code> "meta": {
      "indexable": true
   }
  </code></pre>
  
  <p>Here is a naive attempt at having <code>json_object_keys</code> in where clause, which doesn't work, but illustrates what I'm trying to do.</p>
  
  <pre><code>with entry(fields) as (values('{
    "login": {
      "value": "fred",
      "meta": {
        "indexable": true
      }
    },
    "password_hash": {
      "value": "88a3d1c7463d428f0c44fb22e2d9dc06732d1a4517abb57e2b8f734ce4ef2010",
      "meta": {
        "indexable": false
      }
    }
  }'::jsonb))
  select * from entry where fields-&gt;jsonb_object_keys(fields) @&gt; '{"meta": {"indexable": "true"}}'::jsonb;
  </code></pre>
  
  <p>How can I query on the value of nested object? Can I somehow join the result of <code>json_object_keys</code> with the table iself?</p>