Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a json in clojurescript

Tags:

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?

like image 416
Stephen Olsen Avatar asked Apr 14 '12 21:04

Stephen Olsen


People also ask

How do I create a new JSON?

String message; JSONObject json = new JSONObject(); json. put("test1", "value1"); JSONObject jsonObj = new JSONObject(); jsonObj. put("id", 0); jsonObj. put("name", "testName"); json.

How do I string a JSON?

Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);


1 Answers

Just for the sake of people looking for something similar.

The ClojureScript core now contains a clj->js function.

like image 90
Rodrigo Taboada Avatar answered Sep 18 '22 17:09

Rodrigo Taboada