# JSONB tree contained in another JSONB tree Query possible?

**URL:** https://forum.djangoproject.com/t/jsonb-tree-contained-in-another-jsonb-tree-query-possible/10807
**Category:** Using Django
**Created:** [December 4, 2021, 5:08pm UTC](https://forum.djangoproject.com/t/jsonb-tree-contained-in-another-jsonb-tree-query-possible/10807 "2021-12-04T17:08:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tobiaskatch](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tobiaskatch/32/5991_2.png) [@tobiaskatch](https://forum.djangoproject.com/u/tobiaskatch)
#### Post date: [December 4, 2021, 5:08pm UTC](https://forum.djangoproject.com/t/jsonb-tree-contained-in-another-jsonb-tree-query-possible/10807/1 "2021-12-04T17:08:55Z")

</div>

Hello everyone,

I would like to query based on a contains operation with nested JSONB object. Example:  
{a: {b: c}, c: d} contains {a: b, c: d}  
This query should evaluate to true because b in the left tree contains the b in the right tree despite the fact that the the left b has another child c. Would this work with normal contains operation?

I found one example on the internet which shows that the following should work:

{sizes: [M, L, XL]} contains {sizes: [M, L,]}

According to this, the contains operation is applied recursively to the child fields, do you think also my example above would work?

Thank you for your help!

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [December 5, 2021, 12:26am UTC](https://forum.djangoproject.com/t/jsonb-tree-contained-in-another-jsonb-tree-query-possible/10807/2 "2021-12-05T00:26:43Z")

</div>

This really isn’t a Django question. You might get a more direct and clear answer by asking this in a more PostgreSQL-focused forum. (Once you’ve determined what the PostgreSQL specific answer is, then we can help with a Django-based implementation.)
