Error when using json.Validate()
with a list definition
#2785
Unanswered
joaopenteado
asked this question in
Q&A
Replies: 1 comment
-
I just noticed it's possible to get around this by parsing the JSON in a hidden field and then applying the constraint to that hidden field, like so: import "encoding/json"
#NetworkInterface: {
network: =~"[a-zA-Z0-9-]+"
subnetwork: =~"[a-zA-Z0-9-]+"
tags?: [...=~"^[a-z][a-z0-9-]*[a-z0-9]$"]
}
z: #"[{"network":"vpc","subnetwork":"Subnet","tags":["t1","t2"]}]"#
_z: [...#NetworkInterface]
_z: json.Unmarshal(z) Is there a way to accomplish this without this hidden field? Should this discussion be converted into an issue or is this the expected behavior for the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I've just started learning CUE and I'm trying to use
json.Validate()
against an open list of CUE definitions.This is especially useful to validate certain Kubernetes annotations that are often stringified JSON objects or arrays.
Example code
Playground link
If anyone has encountered a similar issue or has insights on how to resolve this error, I would greatly appreciate your input. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions