7

In my logic app, I have a JSON object (parsed from an API response) and it contains an object array.

How can I find a specific element based on attribute values... Example below where I want to find the (first) active one

{
    "MyList" : [
        {
            "Descrip" : "This is the first item",
            "IsActive" : "N"
        },
        {
            "Descrip" : "This is the second item",
            "IsActive" : "N"
        },
        {
            "Descrip" : "This is the third item",
            "IsActive" : "Y"
        }
   ]
}
Chris Hammond
  • 2,064
  • 5
  • 27
  • 53

2 Answers2

7

Well... The answer is in plain sight ... There's a FILTER ARRAY action, which works on a JSON Object (from PARSE JSON action).. couple this with an @first() expression will give the desired outcome.

enter image description here

Chris Hammond
  • 2,064
  • 5
  • 27
  • 53
2

You can use the Parse JSON Task to parse your JSON and a Condition to filter for the IsActive attribute:

Use the following Schema to parse the JSON:

{
  "type": "object",
  "properties": {
    "MyList": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "Descrip": {
            "type": "string"
          },
          "IsActive": {
            "type": "string"
          }
        },
        "required": [
          "Descrip",
          "IsActive"
        ]
      }
    }
  }
}

Here how it looks like (I included the sample data you provided to test it): enter image description here

Then you can add the Condition:

enter image description here

And perform whatever action you want within the If true section.

Community
  • 1
  • 1
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172