Filter array of strings in Sanity query returning null

23 replies
Last updated: Nov 29, 2025
Anyone able to help me here? I'm trying to filter an array (
platform
) of strings. Tried several ways but they keep returning null
example of what platform would look like ['ios', 'android']


*[_type == 'bannerQueue'] {
  banners[]->{
    _id,
    bannerType,
    "description": description[$lang],
    "imageUrl": image.asset->url,
    platform,
  }
}[0]
AI Update

I can help you with filtering an array of strings in GROQ! Based on your example where platform is an array like ['ios', 'android'], here are the correct ways to filter it:

If you want to filter documents where platform contains a specific value:

*[_type == 'bannerQueue' && "ios" in platform] {
  banners[]->{
    _id,
    bannerType,
    "description": description[$lang],
    "imageUrl": image.asset->url,
    platform,
  }
}[0]

The in operator checks if a value exists in an array. So "ios" in platform returns true if the platform array contains "ios".

If you want to filter banners based on their platform array:

*[_type == 'bannerQueue'] {
  banners[]->{
    _id,
    bannerType,
    "description": description[$lang],
    "imageUrl": image.asset->url,
    platform,
  }["ios" in platform || "android" in platform]
}[0]

Here you're dereferencing the banners first with []->, then filtering the results with another filter that checks if the platform array contains your desired values.

Common reasons for getting null:

  1. Missing the in operator - You need "ios" in platform, not platform == "ios"
  2. Filter placement - Make sure your filter comes after the dereference operator (->) if you're filtering the referenced documents
  3. Array syntax - Remember to use []-> when dereferencing an array of references

The key insight from the GROQ documentation is that the in operator is specifically designed for matching values in arrays: *["sci-fi" in genres] matches all documents where genres is an array containing the value "sci-fi".

Try the first example if you're filtering at the bannerQueue level, or the second if you need to filter the individual banners after dereferencing them!

Show original thread
23 replies

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?