Answers for "read local json file"

1

parse local json file

// pure javascript
let object;
let httpRequest = new XMLHttpRequest(); // asynchronous request
httpRequest.open("GET", "local/path/file.json", true);
httpRequest.send();
httpRequest.addEventListener("readystatechange", function() {
    if (this.readyState === this.DONE) {
      	// when the request has completed
        object = JSON.parse(this.response);
    }
});
Posted by: Guest on November-18-2020
0

how to import json data from a local file

var json = require('./data.json'); //(with path)
Posted by: Guest on August-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language