cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
JamesM
Level 8

Going bonkers trying to access specific JSON array element in FLOW.

I have a JSON response from a Web API that is structured as follows (it was far too large to paste the entire JSON output here). 

 

2018-10-31 16_09_56-JSON Editor Online - view, edit and format JSON online.png

 

I am wanting to access just one of the items in the items array, if its label value = "IT" e.g. this item: 

 

2018-10-31 16_11_48-JSON Editor Online - view, edit and format JSON online.png

 

I am somewhat sure that the Compose action will help here, but I'm at a loss as to how to use it. Basically I will be receiving 100 or so of these JSON outputs, and I want to extract the 'score' from the item whose label is 'IT and store it in an array, ignoring the rest of the JSON.  I tried this but it fails saying I can only refer to an array by an index and I'm not sure how to specify an index: 

 

equals(variables('ITPath')['items']['label'],'IT')

 

Here is the section of the Flow I'm dealing with. 

 

2018-10-31 16_14_31-Microsoft Edge.png

 

In plain English, I just want to

- Obtain each JSON response from the call to the WEB API

- Obtain only the score field from the array of 'items' within the JSON if the label = 'IT' (there should only be one item with this value)

- add the value of the score field to an array. 

 

Later I'll use that array elsewhere, but need to solve this part first 😐

2 REPLIES 2
Community Support Team
Community Support Team

Re: Going bonkers trying to access specific JSON array element in FLOW.

Hi @JamesM,

 

Could you please share more details about the flow?

Could you please share more details about the run history when the flow run failed?

Did your flow run failed in the Compose action?

 

I afraid that your flow run failed in the Compose action, because the variables('ITPath')['items'] is an array, you should add an apply to each to it to get the ['label'].

 

Please refer to screenshot below to create the flow to see if the issue still exists:

Capture.PNG

Capture.PNG

 

The expression in the Initial variable as below:

variables('ITPath')['items']

The expression in the Compose as below:

equals(items('Apply_to_each')?['label'],'IT')

 

 

Please share the full array of the object and the full screenshot of your flow if your issue still exists.

 

 

Best regards,

Alice

JamesM
Level 8

Re: Going bonkers trying to access specific JSON array element in FLOW.

You are correct, the flow fails with Compose, see below:

 

flow1w.png

 

Here is the flow JSON:

 

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "logicAppName": {
      "type": "String",
      "metadata": {
        "description": "Name of the logic app."
      }
    },
    "logicAppLocation": {
      "defaultValue": "[resourceGroup().location]",
      "allowedValues": [
        "eastasia",
        "southeastasia",
        "centralus",
        "eastus",
        "eastus2",
        "westus",
        "northcentralus",
        "southcentralus",
        "northeurope",
        "westeurope",
        "japanwest",
        "japaneast",
        "brazilsouth",
        "australiaeast",
        "australiasoutheast",
        "southindia",
        "centralindia",
        "westindia",
        "canadacentral",
        "canadaeast",
        "westcentralus",
        "westus2",
        "[resourceGroup().location]"
      ],
      "type": "String",
      "metadata": {
        "description": "Location of the logic app."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Logic/workflows",
      "name": "[parameters('logicAppName')]",
      "apiVersion": "2016-06-01",
      "location": "[parameters('logicAppLocation')]",
      "properties": {
        "state": "Disabled",
        "definition": {
          "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
            "$authentication": {
              "defaultValue": {
                
              },
              "type": "SecureObject"
            }
          },
          "triggers": {
            "manual": {
              "type": "Request",
              "kind": "Http",
              "inputs": {
                "schema": {
                  
                }
              }
            }
          },
          "actions": {
            "httpGetAllAudits": {
              "runAfter": {
                "initITportion": [
                  "Succeeded"
                ]
              },
              "type": "Http",
              "inputs": {
                "method": "GET",
                "uri": "https://api.safetyculture.io/audits/search?template=template_25efe48108e84a67b572f20933e488bc&template=template_580c47d97bfe476085e9a471dc928243&template=template_fb87fd58a50c414182c398d51ea5053e",
                "headers": {
                  "Authorization": "Bearer "
                }
              }
            },
            "loopAudits": {
              "foreach": "@variables('iAuditorAudits')['audits']",
              "actions": {
                "httpGetSpecificAudit": {
                  "runAfter": {
                    
                  },
                  "type": "Http",
                  "inputs": {
                    "method": "GET",
                    "uri": "https://api.safetyculture.io/audits/@{items('loopAudits')['audit_id']}",
                    "headers": {
                      "Authorization": "Bearer "
                    }
                  }
                },
                "Set_variable": {
                  "runAfter": {
                    "httpGetSpecificAudit": [
                      "Succeeded"
                    ]
                  },
                  "type": "SetVariable",
                  "inputs": {
                    "name": "ITPath",
                    "value": "@body('httpGetSpecificAudit')"
                  }
                },
                "Compose": {
                  "runAfter": {
                    "Set_variable": [
                      "Succeeded"
                    ]
                  },
                  "type": "Compose",
                  "inputs": "@equals(variables('ITPath')['items']['label'],'IT')"
                },
                "Append_to_array_variable": {
                  "runAfter": {
                    "Compose": [
                      "Succeeded"
                    ]
                  },
                  "type": "AppendToArrayVariable",
                  "inputs": {
                    "name": "ITScoreArray",
                    "value": "@outputs('Compose')"
                  }
                }
              },
              "runAfter": {
                "initiAuditorAudits": [
                  "Succeeded"
                ]
              },
              "type": "Foreach",
              "runtimeConfiguration": {
                "concurrency": {
                  "repetitions": 50
                }
              }
            },
            "initiAuditorAudits": {
              "runAfter": {
                "httpGetAllAudits": [
                  "Succeeded"
                ]
              },
              "type": "InitializeVariable",
              "inputs": {
                "variables": [
                  {
                    "name": "iAuditorAudits",
                    "type": "Object",
                    "value": "@body('httpGetAllAudits')"
                  }
                ]
              }
            },
            "initITScoreArray": {
              "runAfter": {
                
              },
              "type": "InitializeVariable",
              "inputs": {
                "variables": [
                  {
                    "name": "ITScoreArray",
                    "type": "Array"
                  }
                ]
              }
            },
            "initITportion": {
              "runAfter": {
                "initITScoreArray": [
                  "Succeeded"
                ]
              },
              "type": "InitializeVariable",
              "inputs": {
                "variables": [
                  {
                    "name": "ITPath",
                    "type": "Object"
                  }
                ]
              }
            }
          },
          "outputs": {
            
          }
        },
        "parameters": {
          
        },
        "runtimeConfiguration": {
          "collections": {
            "maximumItemCount": 100000
          },
          "performanceProfile": {
            "throttles": {
              "mode": "Medium"
            }
          }
        }
      }
    }
  ]
}

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (4,476)