Struggling with extracting information from a Sanity Client API call and decoding the resulting JSON data. Can someone guide me on how to access specific values?
Below is the output of the API call:
[
{
slug: { current: "test-post", _type: "slug" },
authors: [
{
last_name: "xxx",
profile_picture: "/images/xxx.png",
_key: "xx",
first_name: "xx",
email: "xxx",
_type: "author",
bio: "xxxx ",
},
],
// Other key-value pairs
title: "This is the title of the post2"",
_createdAt: "2023-01-21T23:38:11Z"
},
];
The provided code snippet shows my attempt to process the retrieved data.
const result = await SanityClient.fetch(`*[_type == "post"] | order(publish_date desc)`,);
const document = JSON.stringify(result);
const post:Post = {
title: document['title'],
slug: document['slug.current'],
headline: document[1]['headline'],
publish_date: document['publish_date'],
banner_image: document['banner_image'],
category: document['category'],
author: document['author'],
body: document['body']
}
I'm struggling to understand how to navigate through the properties in the 'document' object. Specifically, unsure about accessing the 'headline' attribute.
Your expertise on this matter would be greatly appreciated!