Skip to content

Instantly share code, notes, and snippets.

@jdoig
Created October 3, 2011 22:34
Show Gist options
  • Save jdoig/1260444 to your computer and use it in GitHub Desktop.
Save jdoig/1260444 to your computer and use it in GitHub Desktop.
XML to Json with some transformation
(ns xml_test.core
(:require [clojure.zip :as zip]
[clojure.xml :as xml]
[clj-json.core :as json])
(:use clojure.contrib.zip-filter.xml))
(defn -main [& args]
(let [paintings (zip/xml-zip (xml/parse "paintings.xml"))]
(->> (xml-> paintings :painting)
(map (fn [painting] { :name (first (xml-> painting :img (attr :alt)))
:caption (first (xml-> painting :caption text))}))
json/generate-string
(spit "paintings.json"))))
@judy2k
Copy link

judy2k commented Oct 4, 2011

Very nice, but what does it /mean/ ;-P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment