How to get into json file in emberjs?


#1

hai i have json file in my local how can add that file data into the ember application


#2

Hai velugu,

  1. Serve that json file through a web server (you can run python -m SimpleHTTPServer 8000 in that directory) so that you can access something like http://localhost:8000/file.json
  1. Override your application adapter to point to whatever backend you chose
  2. Load your models through your routes’ model() hooks

#3

Hai Velugu,

I’m not sure what you’re trying to do exactly because you haven’t explained it clearly in your question. If you just want to access a .json file in your Ember app, you can use Express in /server/mocks/your-things.js to mock a response when your app hits the app/v1/my-things endpoint.

/*jshint node:true*/
module.exports = function(app) {
  var express = require('express');
  var myThingsRouter = express.Router();
  var fs = require('fs');
  var myThings = JSON.parse(
    fs.readFileSync('./app/mocks/fixtures/things.json')
  );

  myThingsRouter.get('/', function(req, res) {
    res.send(myThings);
  });

  app.use('/api/v1/my-things'), myThingsRouter);
};

Read JSON from static file