Search code examples
jsonapimicrosoft-dynamicspower-automate

Expression issues (JSON) with power automate


I'm working on power automate and I have an issue because I've tried a lot expressions and none of them working.

I did a loop (foreach) and inside a message (compose) and there I tried to display "f7626790-0756-43bf-a757-a645a33b853d" from"client"

To do so, I've tried all those expressions:

  • item()?['client']
  • item()?['client']?[0]
  • item()['client']

enter image description here

Here my json file:

[
    {
        "gift": [
            {
                "client": "f7626790-0756-43bf-a757-a645a33b853d",
                "details": [
                    {
                        "client_id": 10859085,
                        "type": "christmas",
                        "application_id": "6e6d758d-8e74-3ae3-ac84-50eb23ae65f"
                    }
                ]
            }
        ]
    }
]

Thank's in advance.


Solution

  • Based on the JSON you provided, you have two arrays. So the question for me is, which array do you want to iterate? Both or the inner one?

    I'm going to assume both or if not, it won't matter if you only ever have one item for both of them, my answer will still retrieve the client property.

    Result

    • The Initialize Data step has your JSON.

    • The Initialize Client step is a blank string at this stage.

    • The For Each Outer Item expression is simply a link to the Data variable as initialized in the first step.

    • The For Each Gift expression is set as ... item()?['gift'] ... as you can work out, that will loop over each gift item.

    • Finally, I get the value of the client property using this expression ... item()['client']