#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.
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.
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'].
🔗 Related Tips
- #PowerPlatformTip 104: Efficient JSON Handling, more techniques for working with JSON in flows.
- #PowerPlatformTip 33: Coalesce, provide clean fallbacks for missing values.
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).