How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Following reference fields in nested arrays with GROQ projection

13 repliesLast updated: Dec 1, 2025

Hey! I am struggling with following reference fields when they are two arrays deep. I have this query:
*[_type == "landingPage" && slug.current == "get-started"][0]{

    landingPageBuilder[] {
      _type == 'industries' => {
          industries[]->{title}
      },
    ...
    }
  }
I would expect that each of the industries (which are an array of references) would be returned with just the
title
. But I only get back the
_ref
,
_key
, and
_type
without the title. Can anyone spot what I am doing wrong?
AI Update

I can see your query syntax industries[]->{title} is actually correct GROQ! The issue is with how conditional projections work within nested array projections.

The problem is that when you use _type == 'industries' => {...} inside an array projection, the conditional completely replaces the object when true. Without the spread operator (...), you only get back what you explicitly define in that conditional block, which is why you're seeing just _ref, _key, and _type without the dereferenced titles.

Here's the corrected query:

*[_type == "landingPage" && slug.current == "get-started"][0]{
  landingPageBuilder[] {
    _type == 'industries' => {
      ...,
      industries[]->{title}
    }
  }
}

Why this works:

Alternative if you only need title strings:

If you want a flat array of title strings instead of objects with title properties:

*[_type == "landingPage" && slug.current == "get-started"][0]{
  landingPageBuilder[] {
    _type == 'industries' => {
      ...,
      "industries": industries[]->title
    }
  }
}

Note the difference: industries[]->title (without curly braces) gives you ["Title 1", "Title 2"], while industries[]->{title} gives you [{title: "Title 1"}, {title: "Title 2"}].

The key takeaway: conditional projections inside array projections need the spread operator to preserve existing fields, otherwise you only get what you explicitly project in the conditional block. Your dereference syntax was correct all along!

Show original thread
13 replies

Was this answer helpful?

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.

Related contributions