CH03-L04 · foundation

Presence, null, and missing values

Check that a member is present before trying to read its value.

General CELRuns hereDocumented
What will I learn?

You can distinguish a missing member from a member whose value is null.

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

Presence and value are different questions. has(user.email) checks whether the selected member exists without reading it first. If it is absent, the conditional operator chooses the fallback. A present member whose value is null is still present.

Read the prepared example

The CEL + JSON rule is:

has(user.email) ? user.email : 'not provided'

Its input is:

{
  "user": {
    "name": "Maya"
  }
}

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. The user map has no email key.
  2. has(user.email) returns false.
  3. The conditional expression returns "not provided".

Your task

  1. Run the initial example.
  2. Add "email": "maya@example.test" to the map or JSON.
  3. Then set the email value to null and observe that presence alone does not guarantee a string.

Expected observation: An added email is returned; a present null value may require an additional value check.

Common mistake

Writing user.email != null reads the member before it proves that the member exists. Use has() when presence is uncertain.

Show the explanation

No. It only tells you that the member is present.

Knowledge check

Does has(user.email) tell you that the email is non-empty text?

Key takeaway

Check presence before access, then validate the value separately when its content matters.

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.