CH01-L01 · foundation

Expressions and values

Run a self-contained CEL expression and an expression with external JSON data.

General CELRuns hereDocumented
What will I learn?

You can distinguish a local CEL binding from a variable supplied through JSON.

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 CEL program is one expression that returns one value. In the first tab, cel.bind() gives a local name to a value for the duration of its final argument. In the second tab, the host supplies the same name through JSON. The rule uses name identically in both cases; only the source of the value changes.

Read the prepared example

The CEL + JSON rule is:

'Hello, ' + name + '!'

Its input is:

{
  "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. name receives the string Maya.
  2. The + operator joins three strings.
  3. The expression returns "Hello, Maya!".

Your task

  1. Run CEL only and confirm the displayed result.
  2. Replace Maya with your name and run it again.
  3. Switch to CEL + JSON, make the same change in JSON, and run the expression.

Expected observation: Both modes return the same greeting when they receive the same name.

Common mistake

Removing the definition of name does not create an empty string. Evaluation fails because CEL does not guess missing values.

Show the explanation

CEL + JSON. The expression contains the rule while JSON contains the input.

Knowledge check

Which tab keeps changing input data outside the CEL expression?

Key takeaway

An expression and its input are separate concerns. A value may be local or supplied by a host, but every referenced name must be defined.

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.