
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand your issue! You want to filter a nested array within a document to get only the single matching vanguard object by its ID, rather than getting an array with empty objects.
The key is to use GROQ's array filtering with projection to select just the matching object from your Vanguards array. Here are a few approaches:
*[_type == "VanguardsList"][0] {
"vanguard": Vanguards[id == $slug][0]
}This returns just the matching vanguard object directly.
*[_type == "VanguardsList"][0].Vanguards[id == $slug][0]This gives you the single vanguard object directly, which is perfect for getStaticProps().
*[_type == "VanguardsList"][0] {
"vanguard": Vanguards[id == $slug][0] {
id,
// ... other fields you want
}
}getStaticProps():export async function getStaticProps({ params }) {
const slug = params.slug; // or however you're getting the id
const query = `*[_type == "VanguardsList"][0].Vanguards[id == $slug][0]`;
const vanguard = await client.fetch(query, { slug });
return {
props: {
vanguard
}
};
}The key differences from what you were likely doing:
[id == $slug] to filter the array to only matching items (where $slug is a parameter you pass to the query)[0] at the end to get the first (and only) match as an object, not an array.Vanguards syntax directly accesses the array propertyThis approach avoids getting an array with empty objects because you're filtering the nested array before the final selection, and [0] returns a single object rather than an array.
If you're still seeing empty objects, make sure:
id field in your vanguard objects matches exactly (case-sensitive)Vanguards (capital V) as shown in your structureSanity 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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store