๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Understanding the change in parser syntax for accessing the first element of an array in the new API update.

3 replies
Last updated: Apr 9, 2024
Hi all! I previously used a query like:
"relatedTask": relatedTasks[].value[0],
that worked nice. In a update of the API it seems to not longer work.
Anyone that could point me out how I can access the first element of the array and get the value?
Apr 9, 2024, 11:17 AM
In the new parser, precedence was swapped, so this means:
relatedTasks[].(value[0])
I.e., the first element of each
.value
of the array. So to accomplish what you have before:
(relatedTasks[].value)[0]
Apr 9, 2024, 11:22 AM
Perfect, thanks! Is it other things like this in the new parser I should know about, or read somewhere?
Apr 9, 2024, 11:31 AM
It's probably in the changelog somewhere, but this was changed in 2021, so I'm not sure I can find it. ๐Ÿ™‚
Apr 9, 2024, 11:48 AM

Sanityโ€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?