Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are three ways you can go about this, it depends what you're most comfortable with &amp; your use case.</p> <p><strong>The first is to store it as a JS Object</strong></p> <p>if your json data is <code>{ "name":"bob" }</code> you could use <code>myjson = {"name":"bob"}</code> in a <code>.js</code> file in the <code>/lib</code> folder and just call <code>myjson</code> when you need it.</p> <p><strong>Using an http call</strong></p> <p>You need the <code>Meteor http</code> package, installed via <code>meteor add http</code>.</p> <p><em>Server Side code</em></p> <pre><code>myobject = HTTP.get(Meteor.absoluteUrl("/myfile.json")).data; </code></pre> <p><em>Client Side Code</em></p> <pre><code>HTTP.get(Meteor.absoluteUrl("/myfile.json"), function(err,result) } console.log(result.data); }); </code></pre> <p>Another way to do it is to fetch the json file ajax style (you would have to put it in your <code>/public</code> folder though and use <code>Meteor.http</code> to call it.</p> <p><strong>Read the file directly</strong></p> <p>Lastly you could read the file directly, you store your <code>myfile.json</code> in a <code>private</code> directory in your project's root:</p> <pre><code>var myjson = {}; myjson = JSON.parse(Assets.getText("myfile.json")); </code></pre> <p>If you want to access this on the client side you would have to interface it with a Meteor.methods and Meteor.call</p> <p>So whichever way you want, the first is the easiest but I'm not too sure how you want to use it or whether you want to pick the file or something</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload