CH03-L02 · foundation

Maps and member access

Read values with dot notation and square brackets.

General CELRuns hereDocumented
What will I learn?

You can choose suitable syntax for a fixed map key.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.

How it works

A map associates keys with values. Dot notation such as user.name is concise for a fixed identifier-like key. Bracket notation such as user["role"] makes the key explicit. Both forms read existing values; a missing key is not silently replaced.

Read the prepared example

The CEL + JSON rule is:

user.name + ' / ' + user['role']

Its input is:

{
  "user": {
    "name": "Maya",
    "role": "editor"
  }
}

The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.

Evaluation step by step

  1. user.name reads "Maya".
  2. user["role"] reads "editor".
  3. String concatenation returns "Maya / editor".

Your task

  1. Run both modes.
  2. Change the role value and confirm the output changes.
  3. Replace role in the expression with missing and inspect the error.

Expected observation: Existing keys return their values; an absent key produces a member-not-available error.

Common mistake

A dot is not object-oriented method dispatch here. It is a convenient field or map-key selection.

Show the explanation

When the key is written as a string or cannot be expressed as a simple identifier.

Knowledge check

When is bracket notation especially useful?

Key takeaway

Maps are key-value collections. Choose a clear access form and do not assume missing keys have default values.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.