-
Originally opened by @khepin in cuelang/cue#656 I've been "gifted" a set of JSON objects that look like this: {
"entities": {
"fe954a40-2af2-4023-8223-1393f8816cab": {...},
"7e50368c-a2f0-4655-bf68-9db1c7a3778b": {...}
}
} And I'm currently validating this with: #UUID: =~"^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$"
entities:[uuid=#UUID]: {
id: uuid
name: string
type: "Human"
} How can I ensure that all the keys in that map are actual {
"entities": {
"fe954a40-2af2-4023-8223-1393f8816cab": {...},
"hello": {...},
1: {...}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Original reply by @mpvl in cuelang/cue#656 (comment)
This can just be done in addition to what you have. If you didn't already have an
|
Beta Was this translation helpful? Give feedback.
-
Original reply by @mpvl in cuelang/cue#656 (comment) Or just
Another common way, btw, is to "close the struct". In that case the below would do the trick. Basically, creating a definition (a field starting with
|
Beta Was this translation helpful? Give feedback.
Original reply by @mpvl in cuelang/cue#656 (comment)
Or just
Another common way, btw, is to "close the struct". In that case the below would do the trick. Basically, creating a definition (a field starting with
#
) has the effect of recursively closing it. That means that any other field that is not already defined, or matches a pattern constraint, is not allowed.