Logic Apps Transform Json Array

33 Views Asked by At

I am getting below Json and want to send request to Teams Chanel , Conection is setup and able to send complete Json Array but i want to send in Format like mention.

Json Recieved

{ "body": [ [ "2024-03-15T06:06:16.299Z", "Res1", "Integ1", "Process1" ], [ "2024-03-15T06:07:19.469Z", "Res2", "Integ2", "Process2" ], [ "2024-03-15T06:08:32.976Z", "Res3", "Integ3", "Process3" ] ] }

Post to Teams Channel

Timestamp- 2024-03-15T06:06:16.299Z
RG- Res1
Service- Integ1
Process- Process1

Timestamp- 2024-03-15T06:07:19.469Z
RG- Res2
Service- Integ2
Process- Process2

Timestamp- 2024-03-15T06:08:32.976Z
RG- Res3
Service- Integ3
Process- Process3

I tried to use triggerBody()?['body'][0]' for TimeStamp but getting exception . Appriciate if I can get some guidance how this can be achived . I am new in logic apps and in learning phase.

enter image description here

1

There are 1 best solutions below

0
10p On BEST ANSWER

You can use the Select action and the join function to achieve the desired result - nothing else is required.

I am assuming that indeed the following request is sent to your Logic App:

{ "body": [ [ "2024-03-15T06:06:16.299Z", "Res1", "Integ1", "Process1" ], [ "2024-03-15T06:07:19.469Z", "Res2", "Integ2", "Process2" ], [ "2024-03-15T06:08:32.976Z", "Res3", "Integ3", "Process3" ] ] }

And not the following:

[ [ "2024-03-15T06:06:16.299Z", "Res1", "Integ1", "Process1" ], [ "2024-03-15T06:07:19.469Z", "Res2", "Integ2", "Process2" ], [ "2024-03-15T06:08:32.976Z", "Res3", "Integ3", "Process3" ] ]

First, the Select action will help you convert the array of arrays into an array of strings.

Code View of the Select action:

{
    "inputs": {
        "from": "@triggerBody()?['body']",
        "select": "@join(item(), '\n')"
    }
}

Screenshot of the result:

enter image description here

Then, the join function will help you convert this array of strings into a string in desired format.

Code View of the Compose action that uses the join function:

{
    "inputs": "@join(body('Select'), '\n\n')"
}

Output of the Compose action:

2024-03-15T06:06:16.299Z
Res1
Integ1
Process1

2024-03-15T06:07:19.469Z
Res2
Integ2
Process2

2024-03-15T06:08:32.976Z
Res3
Integ3
Process3

Screenshot of the result:

enter image description here