Nico
Nico

Reputation: 1081

clojure loop through json data

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?

Upvotes: 2

Views: 833

Answers (1)

sloth
sloth

Reputation: 101042

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")

Upvotes: 4

Related Questions