2

I have a problem parsing json data in a loop. Iam a clojure beginner and need some hint for looping through json data.

The data looks like this:

{"photoset" {"primary" "8455893107", "total" "2", "pages" 1, "perpage" 500, "page" 1, 
"per_page" 500, "photo" 

[{"id" "8455893107", "secret" "1a3236df06", "server" "8087", 
 "farm" 9, "title" "IMG_0137", "isprimary" "1"} 

{"id" "8469482476", "secret" "4c1bf59214",
 "server" "8235", "farm" 9, "title" "HippieBus", "isprimary" "0"}]

, "owner" 
 "93029076@N07", "id" "72157632724688181", "ownername" "clojureB5"}, "stat" "ok"}

What I want to do is loop through the two photos and build a new url with the id and farm value like http://www.flickr.com/farm/id

I know that I can get one value like this:

(-> (get-in (cheshire.core/parse-string (:body picList)) ["photoset" "photo"]) first (get "id"))

But I can I now loop through it?

1 Answer 1

4

You can simply use map.

(->> (get-in data ["photoset" "photo"])
     (map #(str "http://www.flickr.com/" (get % "farm") "/" (get % "id"))))

It will yield the following list:

("http://www.flickr.com/9/8455893107" "http://www.flickr.com/9/8469482476")

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

2 Comments

Just one more question... I would like to apply a function to every url. I tried it with (doseq [x [links]] (println x)) but it takes the list as one string...
Got it: (doseq [e data](prn e))

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.