How to get a value from nested array of object

Krzysztof Nowicki 81 Reputation points
2025-03-06T08:56:57.1833333+00:00

Json Attributes array of objects is dynamic and may change which means I cannot use Parse Json or expression function to count the position and get the value of the key "key": "mserp_dataareaid".

Payload.

{
  "BusinessUnitId": "15b8fcb2-98c7-ee11-907a-0022481b5de0",
  "CorrelationId": "0442be0b-af18-4434-8545-61cbb613eab7",
  "Depth": 1,
  "InitiatingUserAgent": "xxxxxxxxxxxxxxxx",
  "InitiatingUserAzureActiveDirectoryObjectId": "xxxxxxxxxxx",
  "InitiatingUserId": "xxxxxxxxxxxxxxx",
  "InputParameters": [
    {
      "key": "Target",
      "value": {
        "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts",
        "Attributes": [
          {
            "key": "mserp_tolerancefailingaction",
            "value": {
              "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts",
              "Value": 200000000
            }
          },
          {
            "key": "mserp_dataareaid",
            "value": "2002"
          },
          {
            "key": "mserp_engchgengineeringchangeorderproductattributeentityid",
            "value": "00002e57-0000-0000-1c52-005001000000"
          }
        ],
        "EntityState": null,
        "FormattedValues": [],
        "Id": "00002e57-0000-0000-1c52-005001000000",
        "KeyAttributes": [],
        "LogicalName": "mserp_engchgengineeringchangeorderproductattributeentity",
        "RelatedEntities": [],
        "RowVersion": null
      }
    }
  ],
  "IsExecutingOffline": false,
  "IsInTransaction": false,
  "IsOfflinePlayback": false,
  "IsolationMode": 1,
  "MessageName": "OnExternalCreated",
  "Mode": 1,
  "OutputParameters": [],
  "OwningExtension": {
    "Id": "c8d12775-d8f9-ef11-bae3-6045bd0b0c20",
    "KeyAttributes": [],
    "LogicalName": "sdkmessageprocessingstep",
    "Name": null,
    "RowVersion": null
  },
  "ParentContext": null,
  "SecondaryEntityName": "none",
  "SharedVariables": [
    {
      "key": "IsAutoTransact",
      "value": false
    },
    {
      "key": "AcceptLang",
      "value": ""
    }
  ],
  "Stage": 40,
  "UserAzureActiveDirectoryObjectId": "xxxxxxxx",
  "UserId": "xxxxxxxx"
}

Required output is the value from "key": "mserp_dataareaid" which is 2002 in this case.What is the best approach to get this value out, considering Attributes are dynamic values.

Can this be achieved with 'first' expression function?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,389 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RithwikBojja 870 Reputation points Microsoft External Staff
    2025-03-07T13:40:57.2133333+00:00

    Hi @Krzysztof Nowicki,,

    You can use below design which does the work:

    Firstly, sent input in Parse_Json:

    enter image description here

    Schema:

    
    {
    
        "type": "object",
    
        "properties": {
    
            "BusinessUnitId": {
    
                "type": "string"
    
            },
    
            "CorrelationId": {
    
                "type": "string"
    
            },
    
            "Depth": {
    
                "type": "integer"
    
            },
    
            "InitiatingUserAgent": {
    
                "type": "string"
    
            },
    
            "InitiatingUserAzureActiveDirectoryObjectId": {
    
                "type": "string"
    
            },
    
            "InitiatingUserId": {
    
                "type": "string"
    
            },
    
            "InputParameters": {
    
                "type": "array",
    
                "items": {
    
                    "type": "object",
    
                    "properties": {
    
                        "key": {
    
                            "type": "string"
    
                        },
    
                        "value": {
    
                            "type": "object",
    
                            "properties": {
    
                                "__type": {
    
                                    "type": "string"
    
                                },
    
                                "Attributes": {
    
                                    "type": "array",
    
                                    "items": {
    
                                        "type": "object",
    
                                        "properties": {
    
                                            "key": {
    
                                                "type": "string"
    
                                            },
    
                                            "value": {
    
                                                "oneOf": [
    
                                                    {
    
                                                        "type": "object",
    
                                                        "properties": {
    
                                                            "__type": {
    
                                                                "type": "string"
    
                                                            },
    
                                                            "Value": {
    
                                                                "type": "integer"
    
                                                            }
    
                                                        }
    
                                                    },
    
                                                    {
    
                                                        "type": "string"
    
                                                    }
    
                                                ]
    
                                            }
    
                                        },
    
                                        "required": [
    
                                            "key",
    
                                            "value"
    
                                        ]
    
                                    }
    
                                },
    
                                "EntityState": {
    
                                    "type": [
    
                                        "null",
    
                                        "string"
    
                                    ]
    
                                },
    
                                "FormattedValues": {
    
                                    "type": "array",
    
                                    "items": {}
    
                                },
    
                                "Id": {
    
                                    "type": "string"
    
                                },
    
                                "KeyAttributes": {
    
                                    "type": "array",
    
                                    "items": {}
    
                                },
    
                                "LogicalName": {
    
                                    "type": "string"
    
                                },
    
                                "RelatedEntities": {
    
                                    "type": "array",
    
                                    "items": {}
    
                                },
    
                                "RowVersion": {
    
                                    "type": [
    
                                        "null",
    
                                        "string"
    
                                    ]
    
                                }
    
                            }
    
                        }
    
                    },
    
                    "required": [
    
                        "key",
    
                        "value"
    
                    ]
    
                }
    
            },
    
            "IsExecutingOffline": {
    
                "type": "boolean"
    
            },
    
            "IsInTransaction": {
    
                "type": "boolean"
    
            },
    
            "IsOfflinePlayback": {
    
                "type": "boolean"
    
            },
    
            "IsolationMode": {
    
                "type": "integer"
    
            },
    
            "MessageName": {
    
                "type": "string"
    
            },
    
            "Mode": {
    
                "type": "integer"
    
            },
    
            "OutputParameters": {
    
                "type": "array",
    
                "items": {}
    
            },
    
            "OwningExtension": {
    
                "type": "object",
    
                "properties": {
    
                    "Id": {
    
                        "type": "string"
    
                    },
    
                    "KeyAttributes": {
    
                        "type": "array",
    
                        "items": {}
    
                    },
    
                    "LogicalName": {
    
                        "type": "string"
    
                    },
    
                    "Name": {
    
                        "type": [
    
                            "null",
    
                            "string"
    
                        ]
    
                    },
    
                    "RowVersion": {
    
                        "type": [
    
                            "null",
    
                            "string"
    
                        ]
    
                    }
    
                }
    
            },
    
            "ParentContext": {
    
                "oneOf": [
    
                    {
    
                        "type": "null"
    
                    },
    
                    {
    
                        "type": "object"
    
                    }
    
                ]
    
            },
    
            "SecondaryEntityName": {
    
                "type": "string"
    
            },
    
            "SharedVariables": {
    
                "type": "array",
    
                "items": {
    
                    "type": "object",
    
                    "properties": {
    
                        "key": {
    
                            "type": "string"
    
                        },
    
                        "value": {
    
                            "oneOf": [
    
                                {
    
                                    "type": "boolean"
    
                                },
    
                                {
    
                                    "type": "string"
    
                                }
    
                            ]
    
                        }
    
                    },
    
                    "required": [
    
                        "key",
    
                        "value"
    
                    ]
    
                }
    
            },
    
            "Stage": {
    
                "type": "integer"
    
            },
    
            "UserAzureActiveDirectoryObjectId": {
    
                "type": "string"
    
            },
    
            "UserId": {
    
                "type": "string"
    
            }
    
        }
    
    }
    
    

    Then in 1st For each(For each):

    outputs('Parse_JSON')?['body']?['InputParameters']
    

    enter image description here

    2nd for each(For each 1):

    items('For_each')?['value']?['Attributes']
    

    enter image description here

    Then in condition, items('For_each_1')?['key'] is equal to mserp_dataareaid:

    enter image description here

    Then in Compose:

    items('For_each_1').value
    

    enter image description here

    Output:

    enter image description here

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.