How can I pass an Object from Javascript to Python

UPDATE: You can now pass objects freely from Javascript to Python! You can even call methods and access attributes on your JS objects from Python - check out the updated docs for Using Javascript with Anvil.

(original, out of date post follows)
Anvil’s JS interop mostly expects JSON-format data (which it converts into dict/list/number/str/None objects). If you passed a JS object into Python code, the Python wouldn’t know what was safe to do with it!

So, yes, I’m afraid you’ll want to decompose the object into something JSON-friendly containing the information you wanted to pass into Python!

2 Likes