How to Filter on Object Keys in a Nested Object in Groq-Req?

7 replies
Last updated: Mar 31, 2021
I want to filter on object keys in a nested object in the groq-req, how would I go about doing this? I want to only get one language from est_volume by providing a parameter
You can define the dat you want in the response so I guess you could just specify the language like “en” telling the db to only send you that key…
Do you know how to define the query? im stuck, can't find what syntax to use. It currently looks like this:
*[_type == "second_hand"]{
    title,
    carousel_list[]-> {
      carousel_image,
      carousel_item_name,
     	est_volume,
      price,
    }
  }
Ooh I figured it out! Thanks!
*[_type == "second_hand"]{
    title,
    carousel_list[]-> {
      carousel_image,
      carousel_item_name,
      est_volume,
      price,
      est_volume {
         en
      }
    }
  }

summin like this?
Yes, that was it. i got it working like this:
*[_type == "second_hand"]{
    title,
    carousel_list[]-> {
      carousel_image,
      carousel_item_name,
     	est_volume {
      "est_vol": $lang,
    },
      price,
    }
  }
Thanks for help
Great 🙂

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?