Database Reference
In-Depth Information
Reading JSON data into Incanter datasets
Another data format that's becoming increasingly popular is JavaScript Object Notation
(JSON, http://json.org/ ). Like CSV, this is a plain text format, so it's easy for programs to
work with. It provides more information about the data than CSV does, but at the cost of being
more verbose. It also allows the data to be structured in more complicated ways, such as
hierarchies or sequences of hierarchies.
Because JSON is a much richer data model than CSV, we might need to transform the
data. In that case, we can just pull out the information we're interested in and latten the
nested maps before we pass it to Incanter. In this recipe, however, we'll just work with fairly
simple data structures.
Getting ready
First, here are the contents of the Leiningen project.clj ile:
(defproject getting-data "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]
[org.clojure/data.json "0.2.5"]])
Use these libraries in your REPL or program (inside an ns form):
(require '[incanter.core :as i]
'[clojure.data.json :as json]
'[clojure.java.io :as io])
(import '[java.io EOFException])
Moreover, you need some data. For this, I have a ile named delicious-rss-214k.json
and placed it in the folder named data. It contains a number of top-level JSON objects.
For example, the irst one starts like this:
{
"guidislink": false,
"link": "http://designreviver.com/tips/a-collection-of-wordpress-
tutorials-tips-and-themes/",
"title_detail": {
"base": "http://feeds.delicious.com/v2/rss/
recent?min=1&count=100",
"value": "A Collection of Wordpress Tutorials, Tips and Themes
| Design Reviver",
"language": null,
"type": "text/plain"
},
"author": "mccarrd4",
 
Search WWH ::




Custom Search