How to publish a JSON document

I need to publish a collection’s subset as a static JSON page. To be updated every hour or day. What would be the best approach?

The result should be a public eboypix.json file. Something like this probably:

{
  "eboypix": {
    "TTrgN7AGr9fHkDzkv": {
      "url": "http://s3.amazonaws.com/image_01.png",
      "backgroundColor": "rgb(231, 142, 172)"
    },
    "PSuYfevQm9wk7aJXh": {
      "url": "http://s3.amazonaws.com/image_02.png",
      "backgroundColor": "rgb(255, 0, 81)"
    },
    "HfhCuXTdfpwAejpqT": {
      "url": "http://s3.amazonaws.com/image_03.png",
      "backgroundColor": "rgb(100, 20, 20)"
    }
  }
}

Have you considered implementing an API endpoint instead? You could use picker, for example, and then query the collection and write the json to the response.

You could also just use publish normally and then construct a JSON object on the client, and render it using code formatting if your application is higher-level.

1 Like

This is very helpful! I’m now playing with simple:rest — so easy to set up …
That said, is there any reason to go for Picker instead?

Thanks!

1 Like

Hi @c6y, I would do it with restivus

var Api = new Restivus({
     useDefaultAuth: true,
     version: 'v1',
});
Api.addRoute('json', {authRequired: false}, {
    get: function () {
      var data;
      // build your json in data with a collection query and JSON.stringify
     // if you have circular reference use https://www.npmjs.com/package/json-stringify
      return data
    },
});
2 Likes

I used to use Picker, but the author of Picker (and a lot of other really great packages) has retired from Meteor. I would use a different package, for example Restivus mentioned by @lc3t35, or you could use simple rest, or express or something. Picker worked for me, but it’s not being maintained IIRC.

1 Like

Hi, would it still be possible to upload a JSON file to an IP address? I have the initial issue and don’t need to write the JSON in response as the data is handled on the other end. How would one do this? I’m rather new to this all. I have a JSON file that I’d like to upload to a static IP.