Some fields have names that are not valid CUE identifiers. This Commented CUE demonstrates how to refer to these fields, both at CUE’s top level and elsewhere.
data.cue
package example
// data.cue contains fields we want to refer to
// in file.cue
"top level field": "a top-level value"
aStruct: "nested field": "a nested value"
file.cue
package example
// Declare an alias
X="top level field": _
output: {
// Use the alias to refer to a top-level
// field's value
topLevelField: X
// Use index notation to refer to a
// non-top-level field's value
nestedField: aStruct["nested field"]
}
TERMINAL
$ cue export -e output
{
"topLevelField": "a top-level value",
"nestedField": "a nested value"
}
Related content
- How-to Guide: Exporting fields whose names are not valid identifiers