Answer the question
In order to leave comments, you need to log in
How to use file in JSON.parse?
I have a JSON file that changes periodically. How can it be used in JSON.parse without copying the contents of the file every change?
const shop = JSON.parse('/shop.json')
document.write(JSON.stringify(shop.data.featured.name))
Answer the question
In order to leave comments, you need to log in
Don't use document.write()
it - it's evil.
In the markup, insert an empty div where the content will be inserted:
Loading is not instant, asynchronous:<div id="shopdata"></div>
fetch('/shop.json')
.then(response => response.json())
.then(data => document.getElementById("shopdata")
.innerHTML = JSON.stringify(data.data.featured.name))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question