Skip to content Skip to sidebar Skip to footer

How To Use User Json File In Meteor?

I need to know the JSON file usage in Meteor JS. First where the JSON file store in Meteor Folder Structure and How to get JSON Data using Meteor JS and is it JSON file save using

Solution 1:

If you want to read JSON data, you can use the assets api. You can do the following test in any project:

1) Create a file called private/test.json with the following contents:

[{"id":1,"text":"foo"},{"id":2,"text":"bar"}]

2) Read the file contents when the server starts (server/start.js):

Meteor.startup(function() {
  console.log(JSON.parse(Assets.getText('test.json')));
});

Here we are using getText to read the contents of the file (it assumes the file is located in the private directory). Then we are passing the JSON string contents to parse which will return an object.

Note that the file extension (.json) does not matter, however it is conventional to use it.

Post a Comment for "How To Use User Json File In Meteor?"