I have some clojurescript that I want to interop with some javascript libraries. In my clojurescript code I do some analysis and come up with a list of maps. something like
[{:prop1 "value1" :prop2 "value2"}, {:prop1 "something else" :prop2 "etc"}...]
I need to pass this to a javascript functions as
[{prop1: "value1", prop2: "value2}, {..} ...]
I'm not sure how to return a javascript object form my clojurescript function though. Is there a way to serialize nested maps and lists to javascript objects. Or a way to create a new javascript object and then set properties on it?
String message; JSONObject json = new JSONObject(); json. put("test1", "value1"); JSONObject jsonObj = new JSONObject(); jsonObj. put("id", 0); jsonObj. put("name", "testName"); json.
Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);
Just for the sake of people looking for something similar.
The ClojureScript core now contains a clj->js
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With