Answer the question
In order to leave comments, you need to log in
How to output data from json file to html page?
Good afternoon! There is a .json file with data that needs to be displayed on an html page. I googled it, but it didn’t work. Can someone show me a simple example of outputting data from a file with all the libraries needed for this?
Answer the question
In order to leave comments, you need to log in
let jsonData = {"foo":"bar","id":42};
let formattedJson = JSON.stringify(jsonData, null, 4);
document.body.innerHTML += `<pre>${formattedJson}</pre>`;
In fact, JSON is output to React, Angular, and more. JSON is an API.
Here is a typical HTML/JS example:
Name: <span id="name"></span>
Job: <span id="job"></span>
<script>
let data = {"name": "Tom", "job": "programmer"};
document.getElementById('name').innerHTML = data.name;
document.getElementById('job').innerHTML = data.job;
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question