Support arbitrary key on nested objects (e.g. strings with "+" or "$")
I need to store any valid JSON in my fields. The closest type I see is Object, but it has a limitation on property names: they can't contain spaces or any other non-Alpha Numeric symbols other than underscore. My JSON can have keys with spaces and some other symbols like # or &. What are my options?
8 Replies
@aitkn how large could these arbitrary JSON payloads be?
You can use a JavaScript Map for arbitrary string keys, just create it like new Map(…).
The size is not going to be too big. Maybe a few tens of K max, but it can be nested. Converting to/from Maps would be suboptimal. Using javascript/JSON everywhere without conversion was one of the features I am considering Convex for.
I also just try to add Map field via "Add New Document" like that { a: new Map([["a", "abc"]]) } and I can't: "Unsupported contractor Map"
That makes sense. We're discussing supporting arbitrary fields on everything but the top level document, would that suffice or do you require it all the way down? Also, I'm guessing the option of encoding them as bytes / json string loses a lot of the value of convex for you.
As for Maps, that's a known limitation of the dashboard right now, sorry! Doing it from a mutation works.
Yes, the top-level limitation is acceptable. And yes, I would like to avoid any conversion.
Makes sense. Will follow up when we make a call on arbitrary sub-documents, and when that might ship. Thanks for the feedback! It helps us prioritize
Thank you
Arbitrary keys on nested objects is out in 0.19.0 @aitkn - let us know how it works for you!