Can you search in the content of a JSON field

default discord avatar
kobeaertslast year
3

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
    last year

    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
    kobeaertslast year

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


    It does perform queries on

    name="400"

    but not on

    name=400
  • default discord avatar
    ssyberg7 months ago

    I'm actually not seeing this work reliably, I'm wondering if changes in 2.0+ may have broken this?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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