Did you look at the example payload? Just to be sure, the following in the JSON HTTP payload is not called “an array”:
{
...,
"payload_fields": {
"battery": 4774,
"event": "motion",
"light": 39,
"temperature": 21.38
}
}
(The square brackets in the "gateways": [...]
property within metadata
do define an array.)
How this JSON text from the HTTP request is available in your code depends on that code. Sometimes it’s converted into an object on the fly for you, sometimes you’ll need to add some code to parse it and get such object out of it to easily access its properties.
I’d very much recommend to not parse the JSON text yourself, but convert it into an object right away. In JavaScript that’s typically using JSON.parse()
, but might be different in other languages. Google’s Apps Script uses the Google V8 JavaScript Runtime (or Firefox Rhino for existing pre-February 2020 scripts), for which parsing of JSON text is the same, like:
function doPost(e) {
const data = JSON.parse(e.postData.contents);
const fields = data.payload_fields;
const temperature = fields.temperature;
// Or:
// const temperature = data.payload_fields.temperature;
...
}