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 the extension .JSON?. I didn't get any idea about this. Can you please give me suggestions about JSON files or is there any best references for understanding JSON files in Meteor.
JSON BooleansValues in JSON can be true/false.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With