aitkn
aitkn2y ago

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
ballingt
ballingt2y ago
@aitkn how large could these arbitrary JSON payloads be?
ian
ian2y ago
You can use a JavaScript Map for arbitrary string keys, just create it like new Map(…).
aitkn
aitknOP2y ago
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"
ian
ian2y ago
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.
aitkn
aitknOP2y ago
Yes, the top-level limitation is acceptable. And yes, I would like to avoid any conversion.
ian
ian2y ago
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
aitkn
aitknOP2y ago
Thank you
ian
ian2y ago
Arbitrary keys on nested objects is out in 0.19.0 @aitkn - let us know how it works for you!

Did you find this page helpful?