Tutorial: Webhooks and Responses with Parsing (JSON, Mustache, Tokens)

Why not use a JSON parser like this

to extract the data from the JSON you get.

If your response is too long you can use the response template of the webhook to boil it down to the parts you are interested in and then only pass that to the JSON parser on your device.

e.g. to only get the coordinates your response template could look like this

{ "lat": {{coord.lat}}, "lon": {{coord.lon}} }

in order to get a feeling for handlebars you could use an online handlebars parser like this

where you paste your raw response into the context box and type your test template into the template box.
When you then hit the Compile Handlebars Template you’ll see what comes from that.

I didnt under mostly the part when opening and closing.

Don’t worry about that until you really need to.
Start playing and see what it brings you to.

Here is a sample template for a more complex response from

https://api.openweathermap.org/data/2.5/forecast/daily?mode=json&cnt=7&units=metric&q=Oslo,NO&appid=<yourAppID>
{ "city": "{{city.name}}",
  "country": "{{city.country}}"
  "info": [
{{#list}}      { "t_day": {{temp.day}}, {{#weather}}"id": {{id}}, "desc": "{{description}}"{{/weather}} },
{{/list}}
      { "t_day": "", "id": "", "main": "" } 
   ]
}

which would render this

{ "city": "Oslo",
  "country": "NO"
  "info": [
      { "t_day": 1.77, "id": 601, "desc": "snow" },
      { "t_day": 1.23, "id": 616, "desc": "rain and snow" },
      { "t_day": 3.47, "id": 500, "desc": "light rain" },
      { "t_day": 5.24, "id": 500, "desc": "light rain" },
      { "t_day": 2.82, "id": 616, "desc": "rain and snow" },
      { "t_day": 0.24, "id": 616, "desc": "rain and snow" },
      { "t_day": 1.49, "id": 600, "desc": "light snow" },
      { "t_day": "", "id": "", "main": "" } 
   ]
}

There you can see how you can either use dot-notation (e.g. city.name) to extract a “sub-entity” or use the enumeration via {#...} .... {/...}.

A post was split to a new topic: Webhook to JS help