read

added
1.5

ns
clojure.edn

type
function

(read) (read stream) (read opts stream)

Reads the next object from stream, which must be an instance of
java.io.PushbackReader or some derivee.  stream defaults to the
current value of *in*.

Reads data in the edn format (subset of Clojure data):
http://edn-format.org

opts is a map that can include the following keys:
:eof - value to return on end-of-file. When not supplied, eof throws an exception.
:readers  - a map of tag symbols to data-reader functions to be considered before default-data-readers.
When not supplied, only the default-data-readers will be used.
:default - A function of two args, that will, if present and no reader is found for a tag,
be called with the tag and the value.

                ;; See one of the examples for clojure.core/pr for some uncommon Clojure values
;; that cannot be printed then read back to get the original values (or in
;; some cases, cannot be read back at all).

;; If you wish to transmit data that may contain such values, one suggestion
;; is to use the transit library: https://github.com/cognitect/transit-format
            
                ;; Note that it is not possible to pass the result of (clojure.java.io/reader) 
;; directly to (clojure.edn/read):
(require '[clojure.java.io :as io] '[clojure.edn :as edn])
=> nil
(edn/read (io/reader (.getBytes ":edn")))
ClassCastException java.io.BufferedReader cannot be cast to java.io.PushbackReader

;; Instead, you need to construct a java.io.PushbackReader instance
;; and pass that to (edn/read):
(edn/read (java.io.PushbackReader. (io/reader (.getBytes ":edn"))))
=> :edn