How to return both title and value from Sanity list object?
Based on the documentation I found, it sounds like you're working with a string field that has a predefined list of options, where each option has both a title and a value property.
When you define a string field with options in your schema like this:
{
title: 'Genre',
name: 'genre',
type: 'string',
options: {
list: [
{title: 'Sci-Fi', value: 'sci-fi'},
{title: 'Western', value: 'western'}
]
}
}Only the value is stored in your document - this is the expected behavior. The stored data will look like:
{
"_type": "movie",
"_id": "23407q-qwerqyt12",
"genre": "sci-fi"
}The title is only used for display purposes in the Studio interface, while the value is what gets saved to your content.
To access the title in your queries or frontend:
You have a few options:
1. Keep a mapping in your frontend code - Since the list is defined in your schema, you can maintain the same mapping in your frontend to convert values back to titles when displaying them.
2. Use GROQ to map the value - You can create a projection in your GROQ query that maps the value to its title:
*[_type == "movie"] {
_id,
genre,
"genreTitle": select(
genre == "sci-fi" => "Sci-Fi",
genre == "western" => "Western",
"Unknown"
)
}3. Store both title and value - If you absolutely need both stored in the document, you'd need to use an object type instead of a string type with a list, but this changes your data structure significantly and isn't the typical pattern.
The design where only the value is stored is intentional - it keeps your data normalized and makes it easier to change display labels without migrating existing data. The title is purely presentational for the Studio UI.
If you need help with previewing these values in list views in Studio, the documentation has specific guidance on how to display the title in document previews within the Studio interface.
Show original thread9 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.