Types and Values
The following introduces the basic building blocks in Cue.
Cue has the following built in types. They are meant to align with JSON types.
null bool string bytes number list struct | int
Top and Bottom
Top and Bottom are special values in Cue. They form the opposite ends of the value lattice.
_” is top and matches all value. It is also called the “any” value.
_|_” is bottom and represents an error. (this symbol is likely to be replaced with a word in a future version)
Errors result in bottom with a message attached. You can get errors for incomplete types when exporting Cue to data or for conflicts and invalid semantics in your code.
note, not all errors are shown due to an issue
Null coalescing allows us to provide fallback values when errors occur.
This is technically error coalescing since
null is a valid value.
This works by using disjunctions and defaults.
Cue defines two number kinds:
intare whole numbers, implemented as BigInt to represent any value, and can be constrained for byte size (like int64)
numberare decimals numbers, (also not bounded by byte size, also constrainable?), ints are also numbers
Cue has syntactic sugar for writing numbers too:
0bfor hex, octal, and binary
K, M, G, T, Pfor sizing with optional
e/Efor decimal exponents
- Underscores for visual readability for large numbers
Cue strings are valid UTF-8 sequences with some escaping options
The escape sequences are:
There is one more escape for string interpolation which we will see in the next section.
Cue allows you to modify the string delimiters so you can avoid escaping.
Use any number of
# on both ends of normal strings
Bytes are single quoted and base64 encoded when output:
Cue lists have arbitrary elements of mixed types. They can optionally be open and predefine some elements. Mismatched elements result in errors.
Structs are like JSON objects. They are the primary composite type in Cue. They have a set of fields (label: value). By default, they are open and you can add more fields.
Definitions are very similar to structs and are primarily used for schemas. They are closed by default and are not emitted by Cue when exporting.
You can embed structs and definitions within each other as a method to build up values. You can achieve the same with opened structs / definitions and conjunctions, but often we cannot modify what we can embed.
Pattern Matching Constraints
Pattern matching allows you to specify constraints for labels which match a pattern. While limited in matching today, they will be significantly more powerful once the query proposal is accepted and implemented. For now, you can apply a constraint to string labels and use an identifier to set fields if you like.