0

I try to access to JSON file data using Meteor JS. But I'm unable to access it. Can anybody suggest what I'm doing wrong?

Folder Structure :

myapp project/lib folder - myfile.json

myfile.json:

EJSONObj = {
 "first": "John",
 "last": "Doe",
 "age": 39,
 "sex": "M",
 "salary": 70000,
 "registered": true,
 "favorites": 
 {
  "color": "Blue",
  "sport": "Soccer",
  "food": "Spaghetti"
 } 
}

Meteor JS :

if (Meteor.isClient) 
{
    console.log("My JSON File data:"+EJSONObj.age);
}

Error is :

Uncaught ReferenceError: EJSONObj is not defined 
user229044
  • 232,980
  • 40
  • 330
  • 338
Venkat
  • 841
  • 15
  • 31
  • 1
    You can get it to work in the current way, if you rename `myfile.json` to `myfile.js`. See : http://stackoverflow.com/questions/15374066/importing-a-json-file-in-meteor – Tarang Feb 18 '14 at 07:27
  • Oh,okay.But what is use of using Json file in Meteor?.@Akshat. – Venkat Feb 18 '14 at 07:41
  • 1
    `myfile.JSON` is not a JSON file. It is actually a `js` file. A JSON file cannot have an LVALUE in it. So `a = { ... }` is not valid JSON. – musically_ut Feb 18 '14 at 11:07

1 Answers1

0

Meteor has recently introduced the private directory accompanied by an assets API.

The docs are at http://docs.meteor.com/#assets_getText and what it allows you to do is place your text and binary files in the private directory, they don't get served up to the client, and they are accessible to Meteor on the server side.

Since Meteor take all other JS and CSS resources and bundles them, the private directory is a place for other file types which you need to read and use.

Serkan Durusoy
  • 5,447
  • 2
  • 20
  • 39