'Twilio Studio - Select and Parse JSON Using Liquid

In Twilio Studio, I'm making a GET request and am trying to parse JSON and subsequently assign variables based on the parsed JSON. I'm having difficulty doing so with the JSON that is returned.

Essentially I'm trying to set variables from the "Row" that matches the returned JSON (a user dials in, enters their PIN {{widgets.PIN_Entry.Digits}}, the PIN will match a "Row" in the returned JSON from the GET request and we set variables for userID, userEmail, userName, userPin for the matched row).

{
  "DataSource": {
    "Id": "12345",
    "Name": "Dial-In Subscribers",
    "Rows": [
      [
        "EMP-0226",
        "[email protected]",
        "Ron Swanson",
        "00054321"
      ],
      [
        "EMP-0267",
        "[email protected]",
        "Leslie Knope",
        "00012345"
      ]
    ],
    "TotalRows": 2,
    "LastUpdated": "2020-08-26T03:39:42.7670000Z",
    "CompanyId": 12345
  }
}

I can easily do this with JSON Path (not supported by Twilio studio) to select the values I'm looking to set as variables, but I can't figure out how to use Liquid to do this.

userID == $.DataSource.Rows[?(@.includes('00012345'))].[0]

(would return "EMP-0267")

userEmail == $.DataSource.Rows[?(@.includes('00012345'))].[1]

(would return "[email protected]")

userName == $.DataSource.Rows[?(@.includes('00012345'))].[2]

(would return "Leslie Knope)

userPin == $.DataSource.Rows[?(@.includes('00012345'))].[3]

(would return "00012345")

Can anyone share some ideas on how to parse the JSON and set variables using Liquid? Here's how I'm thinking I would accomplish this:

  1. Match the variable {{widgets.PIN_Entry.Digits}} to a row in the returned JSON
  2. Parse the selected row and set variables for userID, userEmail, userName, userPin.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source