Rayy
Rayy12mo ago

How can I define dynamic keys for nested objects in schema?

v.object({
question: v.string(),
answer: v.string(),
yourAnswer: v.optional(v.object({property: v.string()})),
options: v.optional(v.array(v.string())),
})
v.object({
question: v.string(),
answer: v.string(),
yourAnswer: v.optional(v.object({property: v.string()})),
options: v.optional(v.array(v.string())),
})
This is my object, I want the property key to be dynamic of type string, how can I achieve the same in Convex? The yourAnswer object will have this value
{
1: "abc",
2: "def",
...
}
{
1: "abc",
2: "def",
...
}
2 Replies
Michal Srb
Michal Srb12mo ago
This could be possible with a v.record validator which we don't have atm (https://discord.com/channels/1019350475847499849/1169820234862055537/1169822024663826452). As in that thread, we suggest:
v.array(v.object({key: ..., value: ...}))
v.array(v.object({key: ..., value: ...}))
instead (a an array of named tuples representing the keys and values)
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Rayy
RayyOP12mo ago
Ah, okay. Thanks for this tho.

Did you find this page helpful?