JSON object instead of Switch
Quiz question
What are the two ? for in outputs('Status_Options')?[outputs('Input_Value')]?['Title']?
Solution
- A) They prevent an error when a key is unknownCorrect. If the key or the field is missing, the expression returns null instead of an error.
- B) They mark the values as optional inputsWrong. The question mark has nothing to do with inputs. It only protects the access to a property.
- C) They automatically convert the result to textWrong. The question mark does not change the type. For text you need string().
What it is about
A Switch with a dozen cases or Conditions nested three levels deep is hard to read, and every new case means changing the structure of the flow. Often the only goal is to look up a value for a key. For that you store a JSON object with all cases in a Compose action, for example A, B and C, each with a title and a description. You get the matching value with an expression like outputs('Status_Options')?[outputs('Input_Value')]?['Title']. The two question marks prevent an error when the key or the field is missing. With coalesce() you set a fallback value for unknown keys. You add new cases in the JSON, the flow itself stays the same.
The expression from the tip
outputs('Status_Options')?[outputs('Input_Value')]?['Title']When to use it, when not
Use it
When a Switch only looks up values: statuses, texts, addresses or settings per environment.
Better not
When the cases should trigger different actions. Then Switch remains the right tool.
Most common mistake
Not catching unknown keys. Without coalesce(), null travels on and only surfaces much later.
License
Standard This technique uses standard connectors. Microsoft 365 usage rights cover standard connectors. Check the rights for your whole flow. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.
Share
Short link: powerautomate.ninja/en/100
Source: PowerPlatformTip #100, Microsoft Learn: Use data operations in Power Automate.
Prefer to continue with guidance? The Power Automate live course (in German) at the Power Platform Academy runs over four weeks. The next dates are not set yet, you can join the waiting list on the course page.