(read-string s) (read-string opts s)
Reads one object from the string s. Returns nil when s is nil or empty. Reads data in the edn format (subset of Clojure data): http://edn-format.org opts is a map as per clojure.edn/read
;; The following code is a subset of that found at
;; http://www.compoundtheory.com/clojure-edn-walkthrough
;; It illustrates the fact that the readers
;; 'read' and 'read-string' have symmetric writers
;; 'prn' and 'prn-str'.
(ns edn-example.core
(require [clojure.edn :as edn]))
(def sample-map {:foo "bar" :bar "foo"})
;; Here you can see that the 'prn-str' is the writer...
(defn convert-sample-map-to-edn
"Converting a Map to EDN"
[]
;; yep, converting a map to EDN is that simple"
(prn-str sample-map))
(println "Let's convert a map to EDN: " (convert-sample-map-to-edn))
;=> Let's convert a map to EDN: {:foo "bar", :bar "foo"}
;; ...and the reader is 'read-string'
(println "Now let's covert the map back: " (edn/read-string (convert-sample-map-to-edn)))
;=> Now let's covert the map back: {:foo bar, :bar foo}
;; The following demonstrates the use case of edn built-in tagged elements
user=> (class (clojure.edn/read-string "#inst \\"1985-04-12T23:20:50.52Z\\""))
java.util.Date
;; if you want to specify custom processing of some field add tag and function which process it
;; let's assume we have edn with some relative paths and want to make tham absolute
(def config "{:k8s-path #path \\"./infra/k8s\\"}")
(defn absolute [path])
(edn/read-string {:readers {'path absolute}} config)
{:k8s-path "/users/some_user/project/k8s-path"}