Repository navigation
Examples
Home › Examples
- Build and read values
- Insert a whole array
- Read two list items
- Send one object to HomeyScript
- Connect errors
Follow the first example
to build room and temperature. Both values come from the same
Build JSON token; Read gives each its own correctly typed token.
Select the smallest card with enough slots; larger cards can leave paths
unused. To read more than ten values of one type, connect another Read
card to the same JSON token.
- Add Build JSON (5 Json's). Leave Existing JSON empty.
- Enter
readingsin Property Path Json 1. - Paste this into Json 1:
[18, 19, 21]- Connect the JSON output to a Read card's Existing JSON.
Enter
readings[1]in Property Path Number 1.
Expected output: {"readings":[18,19,21]}, then Number 1 = 19.
The JSON input is parsed, so the array is inserted as an array, not as a
quoted piece of text. Use Text 1 instead if you intentionally want
the characters to be stored as text. This does not append to an existing
array; it replaces the specified property.
Given this input to Read JSON (3*3 arguments):
{
"words": ["red", "blue"]
}Set Property Path Text 1 to words[0] and Property Path Text 2
to words[1]. Text 1 is red and Text 2 is blue.
Do not put both paths in one field. This adapts the developer's
community answer.
Install HomeyScript and create a script. Connect Build's JSON output to the script card's argument input. For the first argument, a simple script is:
const data = JSON.parse(args[0]);
console.log(data.room);
return data.room;With the first example, it logs and returns Kitchen. The argument is
JSON text, so parse it once; do not paste untrusted text into executable
code. Use the script card appropriate to your HomeyScript installation.
The community discussion
explains why passing one JSON object is useful.
In Advanced Flow, connect success from Build to Read and the error output to a notification or safe log. Do not feed a failed action's output to the next action. Check the first failing card and retry with a small known example. Avoid including private JSON in notifications or logs. For a list processed item by item, continue with Looping.
Support development - If JSON Handler is useful to you, you can support its
continued development through GitHub Sponsors,
Patreon,
PayPal, or
bunq.
Thank you!