I have a big json file (+-10mb). I want to load in this json file (myjson.json) in a Javascript function located in a HTML webpage. I found a lot of answers on google that s
I think you are looking for FileReader: https://developer.mozilla.org/en-US/docs/Web/API/FileReader
If you have it working, take a look at JSON.parse(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
Unfortunately, both XHR and the Fetch API are inextricably tied to HTTP, and cannot be used to load a resource from a relative path unless an HTTP server is involved. If you're loading your page via a file:
URL, you won't be able to use XHR or Fetch to get that data.
There are only two methods available to you:
Switch to JavaScript instead of regular JSON and use a <script>
tag (as previously suggested to you in another answer)
Allow the user to drag/drop the JSON file (or use <input type="file">
) to get a File reference that you can then load.