# query postgres jsonb field with django orm when is a list of objects

**URL:** <https://forum.djangoproject.com/t/query-postgres-jsonb-field-with-django-orm-when-is-a-list-of-objects/13936>\
**Category:** Using the ORM\
**Created:** [May 26, 2022, 1:46am UTC](https://forum.djangoproject.com/t/query-postgres-jsonb-field-with-django-orm-when-is-a-list-of-objects/13936 "2022-05-26T01:46:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fpitolre](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fpitolre/32/8649_2.png) [@fpitolre](https://forum.djangoproject.com/u/fpitolre)\
**Post date:** [May 26, 2022, 1:46am UTC](https://forum.djangoproject.com/t/query-postgres-jsonb-field-with-django-orm-when-is-a-list-of-objects/13936/1 "2022-05-26T01:46:33Z")

</div>

I have and object similar to his:

```auto
{
"products":[{"cpu":"something here", description:"intel core i9, 30 gb ram"},
{"cpu":"another here", description:"amd raizen, 20 gb ram"}
]
}

```

now i want to search with a “like” something in the description, with direct query on postgres i solve with the next query,

```auto
select distinct id from mytable, JSONB_ARRAY_ELEMENTS(jsonfield->'products') products
where products->>'description' like '%raizen'

```

but now i need to do something similar with django ORM, the only code that i can found is the next one:

```auto
bf = mytableobject.objects.filter(jsonfile __products__ contains=[{"CPU":"0x3"}]).first()

```

the code above works just with an exact equals,but i need a like search, i mean, the next code does not work:

```auto
bf = mytableobject.objects.filter(jsonfile __products__ contains=[{"description":"raizen"}]).first()

```

I found that i can search specifiying the index , something similar to this:

```auto
bf = bucketizerfiles.objects.filter(jsonfile __products__ 0 __description__ contains="raizen").first()

```

in fact this code works, however, i do not know how many products i have in the list and to be honest the solucion of searching index by index is not optimal at all.

so, i want to know if there is a manner to perform a “like” search in a list of object in a jsonfield using django orm

just for clarification, this is not my real information and i do not search in a description, it is just an example of my main problem, avoiding the solution of you need to pass this jsonfield to a structure relation database.

---

<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:** [May 26, 2022, 12:31pm UTC](https://forum.djangoproject.com/t/query-postgres-jsonb-field-with-django-orm-when-is-a-list-of-objects/13936/2 "2022-05-26T12:31:31Z")

</div>

I am not finding any reference or usage of the `jsonb_array_elements` function within Django. You may need to either write a [custom lookup](https://docs.djangoproject.com/en/4.0/howto/custom-lookups/#how-to-write-custom-lookups) or use a raw sql query for this.
