GROQ query: Get array of image URLs from array of objects
Looking at your query, you want to transform the images array to return just the URLs. In GROQ, you can use array projections to map over array elements and extract specific fields. Here's how to do it:
*[_type == "art"]{
_createdAt,
_id,
"category": category.title,
"slug": slug.current,
"featureImage": featureImage.asset->url,
"images": images[].asset->url
}The key is images[].asset->url - this syntax does three things:
images[]- Iterates over each element in the images array.asset->- Follows the reference to the asset document.url- Extracts just the url field
This will give you an images field containing a flat array of URL strings like ["https://...", "https://..."] instead of an array of image objects.
If your images are stored differently (for example, if the URL is directly on the image object rather than on a referenced asset), you might need:
"images": images[].urlOr if they're image objects without references:
"images": images[].asset.urlThe [] operator is really powerful in GROQ - it lets you project through arrays and extract exactly what you need. You can read more about projections in GROQ and check out the query cheat sheet for more array manipulation examples.
Show original thread17 replies
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.