πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

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?