Sanity Schema: Should I Store All Product Variants in Array vs Default Fields?
Your proposed schema approach is actually quite sensible and aligns well with how Sanity handles flexible content structures! There's no technical reason this wouldn't work, and it can be a much cleaner solution for your use case.
Why your approach works well:
Simplicity for simple products - Products without variants just have a single item in the variants array. No need to maintain redundant "default" fields at the product level plus variant-specific fields.
Consistency - All pricing, inventory, and SKU data lives in the same place regardless of whether there's one variant or multiple. Your queries and UI components can treat everything uniformly.
Flexibility - When a product does need variants, you just add more items to the array and populate the "Variants Label" field. The schema doesn't force complexity on products that don't need it.
Things to consider:
Required fields: Make sure your variants array requires at least one item, and consider validation rules to ensure the first (or only) variant has all necessary fields populated.
Display logic: In your Studio, you might want to conditionally hide the "Variants Label" field when the array only has one item, or show a simplified UI for single-variant products.
Query patterns: Your GROQ queries will need to handle the variants array, but this is straightforward. For example, getting the price range:
"priceRange": {"min": min(variants[].price), "max": max(variants[].price)}Frontend logic: Your storefront will always look in the variants array, which is actually simpler than checking "does this product have variants? If yes, look here, if no, look there."
The Shopify-style schema with default fields exists because their data model has constraints that Sanity doesn't. With Sanity's flexible schema system, you can model your content to match your business logic rather than working around platform limitations.
If less than 2% of your products need variants, this approach will make your content editing experience much cleaner for the 98% of cases. Just make sure your Studio UI and validation rules guide editors appropriately for that single-item-array scenario.
Show original thread18 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.