0

Supposing I have this external json:

<script id="data" src="https://website.com/datas.json"></script>

Created with this code:

window.onload = function () {
    var e = document.createElement("script");
    e.setAttribute("id", "data");
    e.src = "https://website.com/datas.json";
    document.getElementsByTagName("head")[0].appendChild(e);
}

How can I get this json content to parse it after ?

This is what I tried:

var data = JSON.parse(document.getElementById('data').innerHTML);

Thanks.

roberto
  • 1
  • 2

1 Answers1

0

you can directly load the json in javascript like below:

const response = await fetch('https://website.com/datas.json');
const data = await response.json();