Today I needed to dynamically access a property on a json message depending what type of message it was. I thought this would be dead straightforward but looking at the action shapes there is a AddProperty and SetProperty but there is no GetProperty. I was looking to see if I could do a json query synatax and also tried various forms of expression with no luck and having a google around seemed to find others with the same issue but no solution.

I was trying to avoid having to call out to a map or function and just wanted to have a fairly simple expression. If you access the outputs from your action below and when you access the key you can use a variable to dynamically set the name of the property you want.

outputs('My Action Name')[variables('MyVariable')]

It turns out when I was playing around with it you can also get even fancier and you can also do a query of the object. I did the below

In the Compose 2 shape I used the below expression using my json query

actions('Compose').outputs[variables('json_query')]

It would be really great if we could get something like a select expression with json query or json path but for the moment this worked for what I needed

 

Buy Me A Coffee