Skip to content

Instantly share code, notes, and snippets.

@mikeflynn
Created March 19, 2012 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeflynn/2127791 to your computer and use it in GitHub Desktop.
Save mikeflynn/2127791 to your computer and use it in GitHub Desktop.
1st clojure script to find the bad json strings in a file.
#_(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