passing json to convex mutation
Do you know of any examples of passing a JSON to a mutation? I am able to accomplish this on the client side of Next.js but not on the server side.
My use case is that after I have finished streaming a structured response in the actions.ts of this Vercel AI SDK tutorial (https://sdk.vercel.ai/examples/next-app/basics/streaming-object-generation), then I want to insert the object (essentially, it's a JSON) in the Convex DB by creating a Convex DB document per JSON element.
I am able to accomplish a successful save on the client side, the app/page.tsx of this tutorial, but only with the end user clicking a save button
4 Replies
You can:
1. Define the args shape and pass the deserialized json to the mutation
2. Use v.any() and pass the deserialized json to the mutation
3. Pass the json string into the mutation and store it as a string
Ah interesting- I missed seeing that any type was available. It is not in the chart in https://docs.convex.dev/functions/args-validation but I see it now in the docs as this sentence: Additionally you can also express type unions, literals, any types, and optional fields.
Argument Validation | Convex Developer Hub
Argument validators ensure that queries,
By the way, @Michal Srb , I could never figure out how to save the partialObjectStream variable from this Vercel AI SDK documentation to Convex DB.
If you come across a successful insertion, let me know!
https://sdk.vercel.ai/docs/reference/ai-sdk-core/stream-object
AI SDK Core: streamObject
API Reference for streamObject
@sshader probably figured that out