title: Find JSON/partial JSON in table
body: <p>Reference: <a href="https://www.postgresql.org/docs/current/functions-json.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/current/functions-json.html</a></p>
  
  <p>I'm looking through this and I'm not seeing what I am looking for, but what I want to do is this. I have a Java application that generates an object:</p>
  
  <pre><code>{"first":"Joe","last":"Doe"}
  </code></pre>
  
  <p>I want to query the database to find json objects with these fields. These fields are NOT static (I could have n fields and they can all be different).</p>
  
  <pre><code>select op.*
  from bw.people p
  where p.object_as_json = '{"first":"Joe","last":"Doe"}' -- this clearly doesn't work
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p><code>object_as_json</code> is now a <code>jsonb</code> data type</p>
  
  <p>One entry in person table, has </p>
  
  <pre><code>object_as_json ='{"first":"Joe","last":"Doe","middle":"S","DOB":"1940-01-01"}'
  </code></pre>
  
  <p>My queries were (neither of these returned anything):</p>
  
  <pre><code>select *
  from bw.people
  where object_in_json = '{"last":"Doe","first":"Joe"}'
  
  select *
  from bw.people
  where object_in_json = '{"first":"Joe","last":"Doe","middle":"S","DOB":"1940-01-01"}'
  </code></pre>