Post

#PowerPlatformTip 128: 'Dynamic Data Retrieval'

#PowerPlatformTip 128: 'Dynamic Data Retrieval'

TL;DR: Pull values from JSON dynamically in Power Automate using Parse JSON with variable keys, no Switch or If cascades.

🧰 Free tool: Working with JSON on the Power Apps side too? Turn a JSON sample into ready-to-use Power Fx (ParseJSON, Type(), ClearCollect/ForAll): ParseJSON in Power Apps converter.

💡 Challenge

Handling dynamic data in Power Automate often pushes you toward sprawling Switch or If structures, one branch per language, user role or message type. That gets hard to maintain fast.

✅ Solution

Use the Parse JSON action together with a dynamic key expression to pull values straight from a JSON structure. You reference the property by a variable instead of hardcoding it, so the same expression returns different content (greetings, settings, user data) based on need.

🔧 How It’s Done

1. Parse your JSON

🔸 Add a Parse JSON action and generate the schema from a sample payload.

2. Reference a value by dynamic key

🔸 Instead of hardcoding, build the property path from a variable, e.g. body('Parse_JSON')?[variables('key')].

3. Drive the key from context

🔸 Set the key from the language, user role or message type so one expression returns the right content.

4. Handle missing keys

🔸 Wrap it with coalesce(body('Parse_JSON')?[variables('key')], 'default') to fall back gracefully.

Power Automate real flow run: a dynamic key "dev" looks up the matching URL directly from a config object without any Switch or If Real flow run: a 3-entry config object (prod/dev/test) plus a runtime key "dev" resolves straight to https://api.dev.com, no Switch/If cascade needed.

Power Automate real flow run: Code View of the dynamic key lookup expression Real flow run: Code View shows the actual expression, @outputs('Config')[outputs('Selected_Key')], the key itself comes from a variable, not a hardcoded property name.

🎉 Result

You get an agile, scalable flow that retrieves and processes data in real time, no cascade of conditions to maintain as new data variations appear.

🌟 Key Advantages

🔸 No complex Switch/If conditions

🔸 Quick to adapt for new data variations

🔸 Flexible across many use cases


🎥 Video Tutorial


🛠️ FAQ

1. How do I generate the JSON schema for the Parse JSON action? Copy a sample JSON payload and use the “Use sample payload to generate schema” button in the action to create the schema automatically.

2. What happens if a key doesn’t exist in the JSON? The Parse JSON action still runs but returns null for missing keys. Use expressions like coalesce() or conditional steps to provide default values.

3. Can I use this approach for nested JSON objects? Yes. Access nested objects by chaining property names, for example body('Parse_JSON')?['data']?['key'].

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.