planck 2017-03-07

almost seems (from your, I imagine, way too simple example) that you could stick a set of parens around the string and read it.

as in (clojure.edn/read (make-stream (str “(” the-thing-to-parse “)”)))

where make-stream is left as an exercise for the interested reader.

@slipset I guess I like to complicate things. The planck test is however for a larger front-end (web, i.e., CLJS) project. Just needed to do some tests w. planck.

New topic. I’ve been given a dataviz project this morning. I need to parse a 15,000,000 row csv file of traffic measurements data and a planck script seems appropriate for the processing/reduction of said data so that it can be mapped affordably (small bandwidth requirements) by client browsers.

Hence this quick question: what would you recommend for conversion of clojure structures into json strings?

This may seem simple but I have never had to deal with clj->json stuff.

So, sorry for what may seem like too simple a question.

Googled for it…

org.clojure/data.json
seems good for that.

Question: is there an equivalent to “planck -c <jar>” for (planck) shell scripts?

On macOS, the shabang mechanism lets you add the desired arguments

Hmmm, as in

#!/usr/bin/env planck -c some.jar
… I hadn’t thought of that. Thanks @mfikes.

Yes. I believe this won’t work on Linux.

Not working it seems (at least for org.clojure/data.json)...

The jar is in my .m2 repository

More precisely:

~/.m2/repository/org/clojure/data.json/0.2.6/data.json-0.2.6.jar

clojure data.json is a Clojure library

Yet,

#!/usr/bin/env planck -c "src:~/.m2/repository/org/clojure/data.json/0.2.6/data.json-0.2.6.jar"

(ns process.core
  (:require [planck.core :as core :refer [slurp *command-line-args*]]
                 [org.clojure/data.json :as json]))
reports
No such namespace: org.clojure/data.json, could not locate org/clojure_SLASH_data/json.cljs, org/clojure_SLASH_data/json.cljc, or Closure namespace “data.json”

Thought that was the problem.

Right; it speaks the truth.

Need to find a cljs-bootstrapped data -> json lib.

Search continues.

Almost too simple. What was I thinking?!

(defn ->json [edn]
  (.stringify js/JSON (clj->js edn)))
and
(defn ->edn [json]
  (js->clj (.parse js/JSON json) :keywordize-keys true))