Setting initial values for array items with image and video object types

13 repliesLast updated: Nov 29, 2025

Is it possible to get initial values from an object like this:
{
  title: "Media",
  name: "media",
  type: "array",
  of: [
    {
      title: "Image",
      type: "image",
    },
    {
      title: "Video",
      type: "object",
      fields: [
        {
          title: "Video Url",
          name: "url",
          type: "url",
        },
        {
          title: "Autoplay",
          name: "autoplay",
          type: "boolean",
        },
        {
          title: "Controls",
          name: "controls",
         type: "boolean",   
        },
      ],
    },
  ],
},

AI Update

Yes, you can definitely set initial values for an array of objects like that! Sanity supports the initialValue property on fields, and it works with arrays of objects too.

For your specific schema, you can add initialValue at the array level. Here's how:

{
  title: "Media",
  name: "media",
  type: "array",
  initialValue: [
    {
      _type: "image",
      // You can't really pre-populate image assets, but the type is set
    },
    {
      _type: "object",
      _key: "video-default", // Arrays need unique _key values
      url: "https://example.com/default-video.mp4",
      autoplay: false,
      controls: true,
    },
  ],
  of: [
    {
      title: "Image",
      type: "image",
    },
    {
      title: "Video",
      type: "object",
      fields: [
        {
          title: "Video Url",
          name: "url",
          type: "url",
        },
        {
          title: "Autoplay",
          name: "autoplay",
          type: "boolean",
          initialValue: false, // Field-level default
        },
        {
          title: "Controls",
          name: "controls",
          type: "boolean",
          initialValue: true, // Field-level default
        },
      ],
    },
  ],
}

A few important notes:

initialValue: () => [{
  _type: "object",
  autoplay: false,
  controls: true,
  url: ""
}]

The field-level approach (setting initialValue on autoplay and controls) is usually the most maintainable solution for your use case, as it ensures every new video object gets sensible defaults without pre-populating the entire array.

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