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

GROQ query: Get array of image URLs from array of objects

17 repliesLast updated: Nov 29, 2025

Hey everyone!Could anyone guide me on how I could do a groq query for an array of objects?

I want images to return an array of images with just their url…
groq`*[_type == "art"]{
      _createdAt,
      _id,
      "category": category.title,
      "slug": slug.current,
      "featureImage": featureImage.asset->url,
      images
    }`
AI Update

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:

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[].url

Or if they're image objects without references:

"images": images[].asset.url

The [] 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 thread
17 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