Return second object in array

Jan de Mul 40 Reputation points
2024-05-23T09:22:18.6066667+00:00

Say I have an output like below, what function could I use to ouput only the first (A) and third (C) elements?

[
  "A=testA",
  "B=testB",
  "C=testC",
  "D=testD",
  "E=testE"
]
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,943 questions
0 comments No comments
{count} votes

Accepted answer
  1. SwathiDhanwada-MSFT 18,131 Reputation points
    2024-05-23T09:34:57.36+00:00

    @Jan de Mul Thanks for reaching out. You can access the elements in below ways either through loop or directly through expression.

    1. Let's say you have stored the output in a variable named "arritems". You can access the value of third item in Compose Action using below expression.
         @variables('arritems')[2]
      
    2. Another way is to loop through the arritems using foreach loop by inputting the arritems variable and with compose action you can access each element using below expression.
         @items('For_each')
      

    Here is sample logic app code reference with the above mentioned examples.

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Compose_1": {
                    "inputs": "@variables('sett')[2]",
                    "runAfter": {
                        "Initialize_variable": [
                            "Succeeded"
                        ]
                    },
                    "type": "Compose"
                },
                "For_each": {
                    "actions": {
                        "Compose": {
                            "inputs": "@items('For_each')",
                            "type": "Compose"
                        }
                    },
                    "foreach": "@variables('sett')",
                    "runAfter": {
                        "Compose_1": [
                            "Succeeded"
                        ]
                    },
                    "type": "Foreach"
                },
                "Initialize_variable": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "sett",
                                "type": "array",
                                "value": [
                                    "A=testA",
                                    "B=testB",
                                    "C=testC",
                                    "D=testD",
                                    "E=testE"
                                ]
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "Recurrence": {
                    "evaluatedRecurrence": {
                        "frequency": "Month",
                        "interval": 3,
                        "timeZone": "India Standard Time"
                    },
                    "recurrence": {
                        "frequency": "Month",
                        "interval": 3,
                        "timeZone": "India Standard Time"
                    },
                    "type": "Recurrence"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {}
            }
        }
    }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful