Search techniques

  • Green belt
  • Standard
  • Tip 100

JSON object instead of Switch

Quiz question

What are the two ? for in outputs('Compose')?[InputValue]?['Title']?

Solution

  1. 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.
  2. 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.
  3. 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('Compose')?[InputValue]?['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('Compose')?[InputValue]?['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 Runs without a premium connector, so the license from Microsoft 365 is enough. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.

Full tip on powerplatformtip.comPowerPlatformTip #100, with screenshots

Prefer to learn with guidance? The Power Automate live course of the Power Platform Academy takes you from the basics to error handling and scopes in four weeks.

Share

Short link: powerautomate.ninja/en/100

Source: PowerPlatformTip #100, Microsoft Learn: Use data operations in Power Automate.