🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Using coalesce in a projection to ensure non-null results in JSON

2 replies
Last updated: May 22, 2023
Hi, I hope someone might be able to help me with hopefully a relatively straightforward problem.
I'm using coalesce in a projection but also wanted to ensure that it's only included in the returned results if it's not null.


{
"strapline": coalesce(strapLine, strapline),
}

May 19, 2023, 2:33 PM
{
  coalesce(strapLine, strapline) != null => {
    "strapline": coalesce(strapLine, strapline),
  }
}

May 19, 2023, 3:42 PM
Thanks Alex!
May 22, 2023, 8:36 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?