sshader
sshader•2y ago

Returning JS objects with hyphens in their keys

...or other symbols Convex doesn't allow as object keys
4 Replies
sshader
sshaderOP•2y ago
Doing a JSON.stringify before returning and a JSON.parse to re-hydrate the return value will work. Map should also accept arbitrary keys. It's nice to have data points around returning JS objects like this / taking them in as function arguments. Convex is being pretty strict right now on what we allow for object keys, but this is good feedback that it could be nice to relax this constraint.
magicseth
magicseth•2y ago
I've got an action that searches unsplash I want to return the nice objects that Unsplash offers from their API so I don't really have much control over their keys 🙂
sshader
sshaderOP•2y ago
Yeah I think your best bet is either doing the JSON.stringify / JSON.parse or iterating through the keys and constructing a Map instead. I totally agree that these are less than ideal and it would be super nice to just return the nice objects you're getting from an external API / generally return arbitrary JSON.
ian
ian•2y ago
Arbitrary keys (including hyphens) should now work in 0.19.0 @magicseth, as long as the field names are not in the top-level document (they're in a nested object). Would love to hear that it works now