'JsonPath Return Array of Concatenated Values from Each Array Element

I'm using a tool that only supports JsonPath commands to extract info from an API response. I have a JSON like the following:

{
  "List": [
    {
      "Name": "Apple",
      "Code": "AAA"
    },
    {
      "Name": "Banana",
      "Code": "BBB"
    },
    {
      "Name": "Cherry",
      "Code": "CCC"
    }
  ]
}

I cannot figure out the correct syntax to return an array with the concatenated "Code - Name" of each array element.

The result I'm trying to get is: ["AAA - Apple", "BBB - Banana", "CCC - Cherry"]

I know how to return an array of one field (e.g. Name) from the List array elements:

<# JsonPath({{body}}, '$.List[0:].Name', true) #>

I'm aware of the concat function but I'm obviously doing something wrong. I tried using:

<# JsonPath({{body}}, '$.List[0:].concat(Code, " - ", Name)', true) #>

but it doesn't actually get the values: [" - "," - "," - "]



Sources

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

Source: Stack Overflow

Solution Source