This Commented CUE demonstrates how to use the built-in function len() to calculate the lengths of different CUE types.

package example

a: len([5, 4, 3, 2])

// Using len() on a string returns the number of
// bytes it contains, not the number of
// characters

// This input is of type bytes
b: len('😎abc123🥶')

// This input is of type string
b: len("😎abc123🥶")
$ cue export
    "a": 4,
    "b": 14
  • Don’t use the len function on a string, for the reason mentioned above.
    How-to Guide: Constrain the length of a string demonstrates using functions from the built-in strings package instead