-
Let's say I have the following json {
"command": "send_email",
"sender": {"name": "John doe", "email": "[email protected]"}
"receiver": {"name": "John smith", "email": "[email protected]"}
} And I have the following structs type Contact struct {
Email string
Name string
}
type Form struct {
Command string
Sender Contact
Receiver Contact
} Is it possible to use zog, or zjson to parse correctly? In Zod, this would be done with the following code: const zContact = z.object({
email: z.string().email(),
name: z.string()
})
const zForm = z.object({
command: z.enum(["send_email"]),
sender: zContact,
receiver: zContact
})
zForm.parse(myJsonForm) |
Beta Was this translation helpful? Give feedback.
Answered by
Oudwins
Jan 11, 2025
Replies: 1 comment 1 reply
-
Yes this should work. What is not yet supported is top level slices in the json (i.e something like [1,2,3]) Have you tried it and had issues? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In fact, this should be very close in Zog: