A function to simplify loading JSON data over the network.
JSON.load(…)”; it can not be called on any instance of JSON.JSON.load('file.json') .then( obj => { console.log(obj) });
This will load the file “file.json” and log its content to the console. It does not provide any error handling yet.
Because this function returns a Promise object, we have access to the optional .catch() and .finally() methods, which are used in this example:
JSON.load('file.json') .then( result => { console.log(result); }) .catch( error => { console.error(error); }) .finally( () => { console.log("All done."); });