EDN

Web Development with Clojure, Third Edition — by Dmitri Sotnikov, Scot Brown (94 / 107)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Appendix 3 Working with EDN and Transit | TOC | Transit 👉

EDN, or extensible data notation, is a data format based on Clojure’s data structure literal syntax. It includes keywords, symbols, strings, numbers, lists, sets, vectors, and maps as covered in Appendix 1, Clojure Primer, along with tags.

Tags are the core differentiator for EDN and are why it’s called extensible data notation.

Tagged Literals

EDN uses the # character as a dispatch, allowing the subsequent form to be parsed in a special way. For example, #_ is discard, which tells the parser to ignore the form that follows. Any # dispatch that has one or more alphabetic characters after it (for example, #uuid) is a tag. This tells the parser to transform the subsequent form based on the tag’s implementation. The built-in #uuid tag converts a string representation of a UUID into the environment’s underlying UUID implementation (for example, java.util.UUID). The #inst tag similarly parses string representations of instants in time.

In addition to the built-in tags, users can specify their own. Any consumers of EDN that contain these custom tags must have the implementation defined to parse correctly, but there’s a default TaggedLiteral type that simply contains the tag name along with the form itself.

Adding Your Own Tags

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.