Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Issue with querying references in Sanity v3.47 resolved

28 replies
Last updated: Jun 20, 2024
Hello. I am having issues with querying references. I keep getting errors in parse response:
Unexpected non-white character after JSON.
I get response if query does not include references and weirdly the reference semi works when there is just one item not array of references. Anyone experiencing similar issues? I have just upgraded to v3.47.
Jun 20, 2024, 2:33 PM
Hey User! Can you send us over the query that is causing the issue?
Jun 20, 2024, 2:38 PM
*[_type == "platformHome"][0]{

_id,

title,

headline,

subheadline,

cards[]{

_key,

title,

subtitle,

platformLink->{"slug": slug.current}

}

}


I am trying to reference link to the page so I query said pages and extract just a slug. It was working before. I had the same issue with image url but it seems to be working now
Jun 20, 2024, 2:57 PM
If you remove all the fields like _id, title, etc and slowly add them back, which one causes the error?
Jun 20, 2024, 3:00 PM
I get response in studio. I use NextJS
Jun 20, 2024, 3:00 PM
At first glance that query looks right
Jun 20, 2024, 3:00 PM
I did it. Only platform link causes the problem
Jun 20, 2024, 3:00 PM
OH WAIT
Jun 20, 2024, 3:01 PM
I SEE
Jun 20, 2024, 3:01 PM
let me test something quick
Jun 20, 2024, 3:01 PM
When I do platformLink-> only, o don’t get the error. But once I query fields in that document it breaks
Jun 20, 2024, 3:01 PM
Just tested other fields. Only slug causes the problem.
Jun 20, 2024, 3:03 PM
platformLink->{slug}

does this work?
Jun 20, 2024, 3:05 PM
platformLink->{slug} is working
Jun 20, 2024, 3:05 PM
Ah okay heres why:
Jun 20, 2024, 3:05 PM
Haha. Just came upWith the same
Jun 20, 2024, 3:05 PM
so not working?
Jun 20, 2024, 3:05 PM
It’s working
Jun 20, 2024, 3:06 PM
Thanks! I used the other solution before and it was working so not sure what changed.
Jun 20, 2024, 3:06 PM
platformLink->{slug}
^^ This works because
slug
is a property of the object already,
slug: slug.current
isnt possible because its a circular dependancy. In Javascript you cant assign something to itself using its own value
Jun 20, 2024, 3:06 PM
No problem! If you did something like
url: slug.current
that would work
Jun 20, 2024, 3:07 PM
Assuming no other field is named url
Jun 20, 2024, 3:07 PM
I found
“slug”: slug.current
in documentation hence used it before. Good to know different approaches.
Jun 20, 2024, 3:08 PM
Really? That surprising that works (and tbh I might be completely wrong but in my brain it makes sense) lol
Jun 20, 2024, 3:09 PM
Can you share where thats from?
Jun 20, 2024, 3:09 PM
I’ll look it up. Can’t remember from top of my head.
Jun 20, 2024, 3:11 PM
Thank you!
Jun 20, 2024, 3:14 PM
But if you test it in studio you get correct response hence I never questioned it.
Jun 20, 2024, 3:15 PM
Hmmm thats wild, good chance my reasoning is wrong if it works inside of vision
Jun 20, 2024, 3:16 PM

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?