2

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
  • 2
    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. Commented Jul 28, 2015 at 6:02

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.