Chris Edwards
Chris Edwards

Reputation: 1558

Clojurescript iterate through JSON array

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.

Upvotes: 2

Views: 1244

Answers (1)

sbensu
sbensu

Reputation: 1521

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

Upvotes: 1

Related Questions