Created
March 19, 2012 22:41
-
-
Save mikeflynn/2127791 to your computer and use it in GitHub Desktop.
1st clojure script to find the bad json strings in a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#_(defdeps ; defeps call for lein oneoff | |
[[org.clojure/clojure "1.3.0"] | |
[clj-json "0.5.0"]]) | |
(ns jsoncheck | |
(:require [clj-json [core :as json]] | |
[clojure.java.io :as io])) | |
(defn processfile [file-name checkfn] | |
"Takes file path and function to parse each line." | |
(with-open [rdr (io/reader file-name)] | |
(doseq [line (line-seq rdr)] | |
(checkfn line)))) | |
(defn parseline [line] | |
"Breaks line, deconstructs a split call and tries to decode the json. Catches exeception and marks it as a failure." | |
(let [[lmi layout] (clojure.string/split line #"\t+")] | |
(try | |
(json/parse-string layout) | |
(catch Exception e (prn lmi))))) | |
(processfile "/Users/mikeflynn/Desktop/keyword_layouts.tsv" parseline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment