Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to Filter out Null Values using GROQ

3 replies
Last updated: May 24, 2022
šŸ‘‹Can I filter out
NULL
values using groq?
I want to use a query like this:

*[_type == "link"] {
  _id,
  title,
  label
}
But if for instance
label
is empty/null, it should be filtered out from the result, instead of showing up as
label: NULL
.
If I do a query like:

*[_type == "link"] {
  ...
}
I get the intended result (except I now query too many unnecessary fields).
May 24, 2022, 9:06 AM
defined(label) => { label }
May 24, 2022, 9:08 AM
Oh, nice šŸ™‚ !
May 24, 2022, 9:10 AM
Thank you!
May 24, 2022, 9:10 AM

Sanityā€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?