Skip to main content
Participating Frequently
Dec 29, 2022 7:10 AM UTC
Question

Dynamic Headers List and Values Into CDT

Hi Team,

I have a requirement that I am getting the data from external system in the form of list of string.

For Example headers: {"name", "Address"}, data: {{"Test 1", "Test2"}} I have to convert this data into list of dictionary like : {{name: "Test 1", Address: "Test2""}}

Since the field headers are also dynamic can you please help any functions or logic to convert the data into list of dictionary.

Thanks in Advance

    2 replies

    harshitb6843
    Brainy
    Dec 29, 2022 7:26 AM UTC

    You can use the below expression unless you have array of array in 'data' because Appian doesn't support list of list (array of array)

    a!localVariables(
      local!doubleQuote: """",
      local!response: {
        headers: { "name", "Address" },
        data: { { "Test 1", "Test2" } }
      },
      local!headers: local!response.headers,
      local!data: local!response.data,
      a!fromJson(
        concat(
          "{",
          joinarray(
            a!forEach(
              items: local!headers,
              expression: concat(
                local!doubleQuote,
                fv!item,
                local!doubleQuote,
                ":",
                local!doubleQuote,
                local!data[fv!index],
                local!doubleQuote
              )
            ),
            ","
          ),
          "}"
        )
      )
    )

    Participating Frequently
    Dec 29, 2022 7:36 AM UTC

    Thanks Harshit the code is working as expected