How to import data from json file to ember app


#1

Hello I am kinda newbie and I am looking to import data I have in my own made json saved at public folder. Can anyone help me how can Import data. here is what my data looks like:

{ “page1”:[ { “url”:“images/pic1.jpg”, “paragraph”:“Some text over picture” } ] }


#2

Hi @Sameed_Baqai, the best place to load data is from a Route’s model hook. For more information about routes please have a look at the guides .

For a start I would recommend that you start without Ember-Data, especially if your App has read-only data only. Just load the data via Ember.$.getJSON (see beneath) and try to render the data inside a template or use the Ember inspector to see what’s happening.

export default Ember.Route.extend({
  model() {
     return Ember.$.getJSON("myurl.json");
  }
});

#3

If the JSON is not a model for a route, then you just keep that in a file (which is static ) and import that file into the route