liveBook · Manning

EDN

As explained in Clojure: The Essential Reference

EDN is an extensible data notation format for encoding Clojure data as text.

EDN (Extensible Data Notation) is a restricted, extensible form of Clojure syntax for transporting data and loading it safely. Use clojure.edn/read for a PushbackReader or clojure.edn/read-string for a string. section 17.0 section 17.6

EDN differs from the general Clojure reader in several deliberate ways:

  • Rejects specialized reader macros such as dereferencing (@), anonymous functions, read-eval, syntax quote, and reader conditionals. section 17.6
  • Ignores :read-cond and :features because reader conditionals are unsupported. section 17.6
  • Accepts :readers, a map from tagged-literal names to implementations; supplied implementations override defaults. section 17.6
  • Accepts :default, which handles tagged literals missing from the default reader tables. section 17.6

Reading ordinary and tagged data

(require '[clojure.edn :as edn]) (edn/read-string "[1 2 3]") ;; [1 2 3] (edn/read-string {:readers {'point identity}} "#point [1 2]") ;; [1 2] (edn/read-string {:default #(format "[Tag '%s', Value %s]" %1 %2)} "#line [[1 2] [3 4]]") ;; "[Tag 'line', Value [[1 2] [3 4]]]" section 17.6

(require '[clojure.edn :as edn]) ; #1
(alias 'core 'clojure.core)

(core/read-string "@#'+") ; #2
;; (clojure.core/deref (var +))

(edn/read-string "@#'+") ; #3
;; RuntimeException Invalid leading character: @

Compare the general Clojure reader with EDN using a dereferencing expression: the former reads it, while EDN rejects the leading @. section 17.6

How Clojure: The Essential Reference covers it

How deep it goes
Explains reader inputs, rejected macros, option differences, and tagged-literal customization through concise executable examples.
Examples
Demonstrates rejected dereferencing syntax, custom #point readers, overriding #inst, and default handling for unknown tags.
What it assumes
Assumes familiarity with Clojure data and syntax while contrasting EDN with the general Clojure reader.
What you can do after
Operate clojure.edn/read-string to parse strings and configure custom or fallback implementations for tagged literals.
How it connects
Connects Clojure syntax with reader macros, tagged literals, clojure.core/read-string, and data serialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.