Database Reference
In-Depth Information
You can download this data ile from Infochimps at http://www.ericrochester.com/
clj-data-analysis/data/delicious-rss-214k.json.xz . You'll need to decompress
it into the data directory.
How to do it…
Once everything's in place, we'll need a couple of functions to make it easier to handle the
multiple JSON objects at the top level of the ile:
1.
We'll need a function that attempts to call a function on an instance of java.
io.Reader and returns nil if there's an EOFException , in case there's a
problem reading the ile:
(defn test-eof [reader f]
(try
(f reader)
(catch EOFException e
nil)))
2.
Now, we'll build on this to repeatedly parse a JSON document from an instance of
java.io.Reader . We do this by repeatedly calling test-eof until eof or until it
returns nil , accumulating the returned values as we go:
(defn read-all-json [reader]
(loop [accum []]
(if-let [record (test-eof reader json/read)]
(recur (conj accum record))
accum)))
3.
Finally, we'll perform the previously mentioned two steps to read the data from
the ile:
(def d (i/to-dataset
(with-open
[r (io/reader
"data/delicious-rss-214k.json")]
(read-all-json r))))
This binds d to a new dataset that contains the information read in from the JSON documents.
 
Search WWH ::




Custom Search