panda - how would i go about validating a datab...
how would i go about validating a database column that is typed as JSON and can have any amount of values in it:
Solution:Jump to solution
they keys will always be strings and the values will always be numbers, so im assuming i would just do
z.record(z.number)
?4 Replies
If it's truly dynamic, you can use
z.any
or z.unknown
to type that property. Or if you know roughly that it'll be a JSON object, but don't know the shape, maybe z.record(z.unknown)
(Which is Record<string, unknown>
) is a slightly easier type to deal with downstream, but that'll break if it ends up being other valid JSON values like an array, null, or a bare JSON primitive like number or string, etc.Solution
they keys will always be strings and the values will always be numbers, so im assuming i would just do
z.record(z.number)
?ahh, yep!
awesome, thanks so much!