How to access the body? #6791
Replies: 2 comments
-
It seems that you are dealing with data in different formats. The import you provided is in JSON format, while the content file appears to be in YAML format commonly used in static site generators like Next.js. To convert the JSON data to JavaScript, you can parse the JSON string using const data = JSON.parse(jsonString); In this case, const jsonString = `{
"attributes": {
"title": "About",
"thumbnail": "img/profile.jpg",
"cats": [
{
"name": "Bob",
"description": "Dig"
}
]
}
}`;
const data = JSON.parse(jsonString); After parsing, you can access the data using JavaScript object syntax: const title = data.attributes.title; // "About"
const thumbnail = data.attributes.thumbnail; // "img/profile.jpg"
const cats = data.attributes.cats; // [{ name: "Bob", description: "Dig" }] Remember to adjust the code according to your specific requirements and how you plan to use the data in your React components. |
Beta Was this translation helpful? Give feedback.
-
Please note my questions is about how to access the body text. Which in my examples is "asldaskjda sldjasldakjs dlaksjd laksdj lasd" |
Beta Was this translation helpful? Give feedback.
-
In my import I am getting this, note the missing body in react
Whereas in my content file I have this
Beta Was this translation helpful? Give feedback.
All reactions