athombv / com.athom.homeyscript

HomeyScript is a JavaScript-based scripting language for Homey that empowers users to unleash their creativity.
https://athombv.github.io/com.athom.homeyscript/
37 stars 12 forks source link

Json Array to be used in Homeyscript #52

Open chrisboer opened 10 months ago

chrisboer commented 10 months ago

It would be nice to get the "Result" from a previous flowcard to be used in a script.

For example

// Your JSON array as a string var jsonString = Resultaat;

// Parse the JSON string into a JavaScript array of objects var dataArray = JSON.parse(jsonString);

// Extract the value associated with "Etdy_ge1" from the dictionary at index 17 var valueAtIndex17 = null; if (dataArray.length > 17 && dataArray[17].key === "Etdy_ge1") { valueAtIndex17 = dataArray[17].value; }

// Parse the value into a number (assuming it's a string representation of a float) var parsedValue = valueAtIndex17 !== null ? parseFloat(valueAtIndex17) : null;

// Print or use the parsed value as needed console.log("Parsed Value:", parsedValue);

jeroenwienk commented 6 months ago

It would be nice to get the "Result" from a previous flowcard to be used in a script.

For example

// Your JSON array as a string var jsonString = Resultaat;

// Parse the JSON string into a JavaScript array of objects var dataArray = JSON.parse(jsonString);

// Extract the value associated with "Etdy_ge1" from the dictionary at index 17 var valueAtIndex17 = null; if (dataArray.length > 17 && dataArray[17].key === "Etdy_ge1") { valueAtIndex17 = dataArray[17].value; }

// Parse the value into a number (assuming it's a string representation of a float) var parsedValue = valueAtIndex17 !== null ? parseFloat(valueAtIndex17) : null;

// Print or use the parsed value as needed console.log("Parsed Value:", parsedValue);

You can do this with Advanced Flows.