Skip to Content

UI5 Not able to load a JSON file.

We are using the eclipse IDE and have a standard project set up. However, we are able to load in a json file. The statement that performs the load does not cause an error as such, as processing continues, but we do get a 404 error in the console when debugging.

I json file is stored in the 'model' subdirectory of the project, and the json file is called Testmodel.json. We have tried:

var oModel1 = new sap.ui.model.json.JSONModel("Testmodel.json");
var oModel1 = new sap.ui.model.json.JSONModel("model/Testmodel.json");

And we have attempted to load it by setting the model in the manifest, but alas no joy.

I'm pretty sure it's some kind of resource issue. Our resource settings in the index.html are:

data-sap-ui-resourceroots='{"tabLayout": ""}'

But so far nothing I can do will load a json file.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Mar 24, 2017 at 01:51 PM

    Hi Gary,

    While defining the path please maintain like this "/projectname/model/testmodel.json".

    Kindly check and let me know if there is any issue.


    Deepak Raj.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 24, 2017 at 03:17 PM

    Hi Gary,

    Normally the structure for your application will be like this projectname/webapp/model/yourjsonfile.json
    in model folder you will keep your json file. If structure is like above you can use try like this

    var oModel=new sap.ui.model.json.JSONModel("projectname/webapp/model/yourjsonfile.json");if you want to bind this  to any control then get the id of that control and bind like this

    //model without name

    var selectid= this.getView().byId("controlsidtobind").setModel(oModel);Thanks,Abul Ehtesham
    Abul Ehtesham
    Add comment
    10|10000 characters needed characters exceeded

  • Mar 24, 2017 at 03:23 PM

    var oRootPath ="replace.with.your.namesapce"); //could be "tabLayout" in your case

    YOURJSONMODEL.loadData(oRootPath + "/model/Testmodel.json", null, false);

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 24, 2017 at 03:39 PM

    Thanks to everyone that replied. I have actually tried all those options, of which none worked. However, I have resolved it, and it was incredibly simple, but cause so much grief.

    In out index.html file we had an entry saying:

    data-sap-ui-resourceroots='{"tabLayout": ""}'

    Which we changed it to:

    data-sap-ui-resourceroots='{"tabLayout": "."}'

    with the full-stop having the effect. We had previously tried this with “./”, but that did not work.

    So now our json file can be loaded via all of the methods I mentioned in my post, including declaring a model in the manifest.

    Regards to all.

    Add comment
    10|10000 characters needed characters exceeded