load-json-xhr

Load json in the browser.

Usage no npm install needed!

<script type="module">
  import loadJsonXhr from 'https://cdn.skypack.dev/load-json-xhr';
</script>

README

load-json-xhr

stable

Loads a JSON file from a URI using xhr. The return object is the XMLHttpRequest.

var load = require('load-json-xhr');

load('my-file.json', function(err, data) {
    if (err)
        throw err;
    console.log(data.foo.bar);
})

Also accepts an options object which is passed along to the xhr module.

var load = require('load-json-xhr');

load({ uri: 'my-file.json', timeout: 5000 }, function(err, data) {
    if (err)
        throw err;
    console.log(data.foo.bar);
})

Usage

NPM

getJSON(opt[, callback])

Gets JSON data from a uri specified in opt. Or you can pass a string.

License

MIT, see LICENSE.md for details.