Clarification on attribute count in Sanity.io for nested objects with different keys.

5 replies
Last updated: Mar 14, 2024
Hi there,I need a help regrading attribute limit count . As I have reached my max limit of 4k in sanity so just need to confirm one thing regarding unique paths

Let's say I have 2 documents and in each document fields are almost same but they are nested under different objects .

For Example:-
1.
Page1:{ title:'Sanity' ,subtitle:'Sanity'}
2.
Page2:{title:'Sanity' , subtitle:'Sanity'}
So in the above example the attribute count would be 6 or is it 3 ?
AI Update

Great question about how Sanity counts unique attribute paths! Let me clarify this for you based on the official documentation on attribute limits.

In your example with two documents:

Page1: { title: 'Sanity', subtitle: 'Sanity' }
Page2: { title: 'Sanity', subtitle: 'Sanity' }

The answer is more than 3 - it would be approximately 4-6 attributes depending on the system fields.

Here's the key principle: Sanity counts unique paths, not individual field instances. According to the documentation, a path is counted based on its unique combination of attribute name and datatype. The documentation provides this example:

{
  "foo": [
    {
      "bar": ...,
      "baz": ...
    },
    {
      "bat": {
        "bar": ...
      }
    }
  ]
}

This structure contains six unique paths:

  • foo (array)
  • foo[] (object)
  • foo[].bar (string)
  • foo[].baz (string)
  • foo[].bat (object)
  • foo[].bat.bar (string)

For your specific example:

In your two documents, you'd have:

  1. _id (system field)
  2. _type (system field)
  3. title (your field)
  4. subtitle (your field)

Plus potentially other system fields like _createdAt, _updatedAt, etc.

The crucial point: Even though you have TWO documents with the same fields, each unique path is only counted once. Using the same field across 1 document or 1,000 documents doesn't increase your attribute count.

Important clarifications:

  • Nested paths count separately: If your fields are nested under different objects (like Page1.content.title vs Page2.metadata.title), those ARE counted as separate paths
  • Only actual content counts: Just defining fields in your schema doesn't increase the count until you actually store data in those fields
  • Paths are reusable: The same path used multiple times across documents only counts once

If you're hitting your 4K limit:

You can check your current attribute count at: https://<projectId>.api.sanity.io/v1/data/stats/<datasetName> (look for fields.count.value)

Common causes of hitting the limit include:

  • Deeply nested structures (especially with block content)
  • Field-level translations/localization (creates multiplier effect)
  • Many different document types with unique fields

Consider using document-level localization instead of field-level, and arrays instead of deeply nested objects for page builders to keep your attribute count manageable.

Are page 1 and page 2 different
_types
?
Hey
user M
Actually its not Page1 and Page2. They both fall under _type "Page" which is array of objects and each object has a different name but same fields in it so It will create unique path always which increases my attribute count right ?For Example
Page:[
{
object_1_name:{ title:'Sanity', subtitle:'Astro'}
},

{
object_2_name
:{title:'Sanity' , subtitle:'Astro'}}
]
So here attribute count will be different for first and second object because key_name is different ? Total for first - 3 and for second - 3
Ah yes, since they’re under a different key in the object, each will be a unique path.
Thanks for help

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?