Cannot get value form JSON object in a sveltekit loop

Hey @carey,

That helps a lot. It should work if you replace the <script> tag in /src/index.svelte with this:

<script context="module">
	import Client from './../../utils/client';
	import PrismicDom from 'prismic-dom';
	import Prismic from '@prismicio/client'

	export async function load() {
		const document = await Client.query(Prismic.Predicates.at("document.type", "accounts"));
		return {
			props: {
				document,
			}
		};
	}
</script>

The issue is that your results includes all documents, including your timezone. The timezone doesn't have a last_name, so it errors.

To query documents by type, use Client.query(Prismic.Predicates.at("document.type", "accounts")). To learn more about predicate queries, you can check out our Rest API docs. (Though most people only ever need to use predicates to query by type, so we're adding getByType() in our next version of the Client package.)

Let me know if that helps, or if you have any more questions. I'm off this afternoon, but I'll be back on Monday.

Sam

1 Like