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

17 replies
Last updated: Jan 22, 2026
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:

  1. images[] - Iterates over each element in the images array
  2. .asset-> - Follows the reference to the asset document
  3. .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[].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

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.

Was this answer helpful?