Using an external JSON file to define options for a list in a Sanity schema file
Good news – yes, you can absolutely import an external JSON file to define options for your schema! This is a common pattern and keeps your configuration DRY.
Since your schema files are just JavaScript/TypeScript modules, you can import JSON files directly at the top of your schema file and use that data to populate the options.list property. Here's how:
1. Import your JSON file:
import { defineField, defineType } from 'sanity'
import myOptions from '../path/to/your-11ty-data-file.json'2. Use it in your schema:
export default defineType({
name: 'myDocument',
type: 'document',
fields: [
defineField({
name: 'tags',
type: 'array',
of: [{ type: 'string' }],
options: {
layout: 'checkbox',
list: myOptions.map(option => ({
title: option.label, // or whatever your JSON structure uses
value: option.value
}))
}
})
]
})Important notes:
- The
options.listarray expects objects withtitleandvalueproperties - If your JSON is already in that format, you can use it directly:
list: myOptions - If it's just an array of strings, you can map it:
list: myOptions.map(opt => ({ title: opt, value: opt })) - Make sure your JSON file is in a location that your Sanity Studio build process can access
For the checkbox layout specifically, set layout: 'checkbox' in the options (as shown above). This works great for arrays of strings where you want multiple selections displayed as checkboxes rather than a dropdown or tags input.
This approach keeps your options in one place (your 11ty _data file), and both your frontend and Sanity Studio will reference the same source of truth. Just remember that if you update the JSON file, you'll need to restart your Studio dev server to see the changes reflected.
There's a Sanity Answers thread that discusses this exact use case if you want to see more examples!
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.