Skip to content

Instantly share code, notes, and snippets.

@gardnervickers
Last active August 29, 2015 14:23
Show Gist options
  • Save gardnervickers/178f4c4ac0607f6275c5 to your computer and use it in GitHub Desktop.
Save gardnervickers/178f4c4ac0607f6275c5 to your computer and use it in GitHub Desktop.
Read json file and parse to edn with core.async
(defn try-parse [x]
(try
(json/parse-string x true)
(catch Exception e
x)))
(defn lazy-test-data []
"Returns a channel that reads json maps line by line from mock_data.json "
(let [channel (chan 5 (map try-parse))]
(future (with-open [rdr (clojure.java.io/reader "resources/mock_data.json")]
(doseq [line (line-seq rdr)]
(>!! channel line)))
(>!! channel :done)
(close! channel))
channel))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment