Skip to content

Instantly share code, notes, and snippets.

@minimal
Created January 4, 2014 14:10
Show Gist options
  • Save minimal/8255710 to your computer and use it in GitHub Desktop.
Save minimal/8255710 to your computer and use it in GitHub Desktop.
Load json from Netflix PigPen
(ns pigpen-exp.core
(:require [pigpen.core :as pig]
[pigpen.raw :as raw]
[clojure.data.json])
(:gen-class))
(defmacro load-json
"Loads json data from a file. Each line should contain one value and
will be parsed using clojure.data.json/read-str into a value. Keys are
converted to keywords.
Example:
(load-json \"input.json\")
See also: pigpen.core/load-clj
"
[location]
`(->
(raw/load$ ~location '~['value] raw/default-storage {:cast "chararray"})
(raw/bind$ '(pigpen.pig/map->bind
#(clojure.data.json/read-str % :key-fn clojure.core/keyword))
{:requires '[clojure.data.json], :field-type-in :native})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment