Search code examples
twiliotwilio-api

Twilio Studio - How To Access Array Items From JSON Output of Function


I'm calling the function below in Twilio Studio from a run function widget, then saving the EmployeeInfo to a variable setting the EmployeeInfo variable to value {{widgets.function_1.parsed.EmployeeInfo}} . When I put the code {{flow.variables.EmployeeInfo}} into a say/play widget it will say all of the data elements but I'm having trouble accessing a single value (like saying a single Name). I tried every conceivable syntax I could think of such as {{flow.variables.EmployeeInfo[0].Name}} and {{flow.variables.EmployeeInfo.Name[0]}} but nothing will play. Do I have some syntax error somewhere, or maybe are you not able to store arrays in variables?

exports.handler = function(context, event, callback) {
  
  let results = {
                 LastName: "WAYNE",
                 FirstName: "BRUCE",
                 EmployeeInfo: [{  ID: 1, Name:"test" }, {  ID: 2, Name:"tested" }, {  ID: 3, Name:"testing" }]
                 };

  return callback(null, results);
};

Solution

  • I am just learning twilio studio flows as well and found that the systax is "{{widgets..parsed.EmployeeInfo[0].Name}}"