How to read a JSON file located in the project directory

I have an external JSON file that I would like to load and read the contents of. I downloaded the cordova-plugin-file and I’m trying to read this file using the plugin. However I’m not sure where the JSON file needs to be placed in the ionic project. I assume it needs to be somewhere in the www folder. I created a ‘data’ folder with a path that would be www/data/myfile.json. I’ve tried various approaches to read this file and all of them have failed to find it.

$cordovaFile.checkFile(cordova.file.dataDirectory, "myFile.json")
      .then(function(success) {
              alert("Successfully found the directory");
      }, function (error) {
            alert("Failed to find the directory");

I’ve tried different directories including: dataDirectory, applicationDirectory, and applicationStorageDirectory. However all of these directories give me the error callback. If anyone has tips or suggestions on how to properly read a file that is located within the project directory that would be much appreciated.


Go to angularjs and check out $http.get(). There’s your answer write there.

1 Like

This worked for me, thanks!