I am trying to create one HTML file that has JSON data embedded in it. The one file can then use the JSON data to create HTML such as a table and so forth.
I have tried template literals, but I'm not sure if I am doing it correctly or what I am missing. This the first time I'm doing this, so I'm not sure how to proceed.
Here's a basic example that I saved as sample.html
const person = {
name: 'Test',
job: 'A job',
city: 'a city',
bio: 'What a test that I'm doing!'
}
// And then create our markup:
const markup = `
<div class="person">
<h2>
${person.name}
</h2>
<p class="location">${person.location}</p>
<p class="bio">${person.bio}</p>
</div>`;
When I view the results, I only see the JSON string and the literal ${person.name} instead of the data within the JSON string. I want it to extract'Test', 'A City', 'What a test that I'm doing' from the Json and then display it using HTML. However, it should all live in one document. Thank you in advance for viewing my question!