Load local Json in new version

How to load local json file in js instead of HTTP json? Thanks!

You could use BundleFile class: https://www.fusetools.com/developers/api/uno/bundlefile

BundleFile file = import BundleFile("Assets/data.json");
var reader = JsonReader.Parse(file.ReadAllText());

Minerals App Development Team: Currently it is not possible in FuseJS, you have to use Uno like Alexander bladyko suggests.

We are working rapidly on expanding the FuseJS APIs, so I’m sure we’ll ship support for this shortly!

Anders Lassen: Thanks for your reply. I look forward to the new update. :slight_smile:

Is this working now?

Try something like this:

var storage = require('FuseJS/Storage');
var obj;
storage.read("filename.json").then(function(content) {
    console.log(content);
    obj = JSON.parse(content);
}, function(error) {
    console.log(error);
    obj = {};
});

Not working Mr.Bjorn

Arunvel: you’re going to have to give us some more information to go on here. What isn’t working? How does it fail? Is there an error? What does the debug output say? What version of Fuse are you using? Which target are you trying this for? Etc.

You need to save the file first, storage is for files that your app first stores and then wants to read. If you want to read a file in your bundle, this is what @Jake suggests:

jake [2:26 AM] if you want it to be in a separate file, you can put it in a separate .js file and expose it with module.exports

​[2:27] then you can require it like any other external JS module

​[2:28] as an example:

​[2:31] take your json and put it into a .js file, like this:

module.exports = // your json

Then in a ux file, import it like this:

<JavaScript File="MyJson.js" ux:Global="MyJson" />

Finally, in JS:

var MyJson = require("MyJson");

// At this point MyJson now represents the object from your JSON