Skip to content

Instantly share code, notes, and snippets.

@taylorwood
Last active May 6, 2020 00:19
Show Gist options
  • Save taylorwood/23d370f70b8b09dbf6d31cd4f27d31ff to your computer and use it in GitHub Desktop.
Save taylorwood/23d370f70b8b09dbf6d31cd4f27d31ff to your computer and use it in GitHub Desktop.
clj.native-image CLI JSON-to-EDN example

GraalVM native image deps.edn example

A CLI tool that reads JSON from stdin then writes it to stdout in EDN format.

Build

➜ clojure -A:native-image

Run

➜ echo "{\"foo\": [{\"bar\": 1.33}]}" | ./core
{:foo [{:bar 1.33}]}
;; IMPORTANT! place this file under src directory
(ns core
(:require
[clojure.data.json :as json]
[clojure.edn :as edn])
(:gen-class))
(defn -main [& args]
(if (string? (first args))
(prn (json/read-str (slurp (first args)) :key-fn keyword))
(prn (json/read *in* :key-fn keyword))))
{:deps {org.clojure/data.json {:mvn/version "0.2.6"}}
:aliases {:native-image
{:extra-deps
:main-opts ["-m clj.native-image core"
"-H:Name=json2edn"]
{clj.native-image
#_{:local/root "/path/to/clj.native-image"}
{:git/url "https://github.com/taylorwood/clj.native-image.git"
:sha "0f113d46f9f0d07e8a29545c636431ddf5360a7d"
:tag "v0.0.3"}}}}
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment