B
B
barabash20902019-07-05 00:10:44
JavaScript
barabash2090, 2019-07-05 00:10:44

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

3 answer(s)
S
Stalker_RED, 2019-07-05
@barabash2090

let jsonData = {"foo":"bar","id":42};
let formattedJson = JSON.stringify(jsonData, null, 4);
document.body.innerHTML += `<pre>${formattedJson}</pre>`;

O
Oval Enoc, 2019-07-05
@ovalenko

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>

N
Nikita, 2019-07-05
@fwervbyberstvrstrf

For example, you can collect data in json into a PHP variable, and display the PHP variable in HTML.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question