2
votes

Given I have a JSON Array such as:

[ { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" } ]

In clojure script how can I iterate through the array and extract the value of each email tag.

in clojure I have the following:

(doseq [record (method that gets json data) true)]
    (do-something (:email record))
  )

which works as expected, however in Clojurescript if I do the same instead of returning the expected result, it simply returns each character in the JSON string as on its own e.g.:

[
{
"
...

Alls I want is a way to return the value of each email element and pass them to a function.

1
It is probably because in clojurescript you are passing in a string, which is also a sequence and when you iterate over it it returns char by char. Maybe if you post here your exact code, someone can give you exact answer. Currently your code wouldn't even compile. - Viktor K.

1 Answers

1
votes

Provided you have a JSON object and not a string, the function your are looking for is js->clj[1]. After using it you can use regular ClojureScript to manipulate. If your JSON is serialized, you should use the Browsers facilities to read it first, as in JSON.parse()[2]

[1] https://crossclj.info/fun/cljs.core.cljs/js-%3Eclj.htm(https://crossclj.info/fun/cljs.core.cljs/js-%3Eclj.html [2] https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse