Can you search in the content of a JSON field

default discord avatar
kobeaerts
7 months ago
2

As the title says, is it possible to search a JSON field through the REST Api?



For example I have a JSON field

specifications

with a content like this


{"category": "birds", "subcategory": "flying birds"}


Can I specifiy I only want collections where the

specifications.category

equals "birds"?



The real JSON content will be like the specifications in this gist:

https://gist.github.com/kobeaerts/3105beaa41200a7415a9796d4eab9599
  • discord user avatar
    denolfe
    Payload Team
    7 months ago

    Yes, you can use dot notation. It would be something like this:

    /api/collection-name?where[specifications.category][equals]=flying birds


    CleanShot_2023-04-21_at_15.55.34.png
    CleanShot_2023-04-21_at_15.55.50.png
  • default discord avatar
    kobeaerts
    7 months ago

    Aha, @denolfe that does indeed work but only with string values.


    It does perform queries on

    name="400"

    but not on

    name=400
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.