Skip to content

Instantly share code, notes, and snippets.

@romulo-martins
Last active June 12, 2023 12:26
Show Gist options
  • Select an option

  • Save romulo-martins/1dc1f744d89f522805ae2901d8eaa6cb to your computer and use it in GitHub Desktop.

Select an option

Save romulo-martins/1dc1f744d89f522805ae2901d8eaa6cb to your computer and use it in GitHub Desktop.
Converts from CSV to EDN file
(require '[clojure.data.csv :as csv]
'[clojure.java.io :as io]
'[clojure.string :as str])
(def in-filename "input-filename.csv")
(def out-filename "output-filename.edn")
(let [csv-data (with-open [reader (io/reader (io/resource in-filename))]
(doall
(csv/read-csv reader)))
maps-data (map zipmap
(->> (first csv-data) ;; First row is the header
(map #(str/replace % #"_" "-")) ;; Example, converts from bla_bla to bla-bla
(map keyword)
repeat)
(rest csv-data))]
(with-open [writer (io/writer out-filename :append true)]
(run!
(fn [row-data]
(.write writer (str row-data "\n")))
maps-data)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment