Clojure:
Working with TOML

How to:

To work with TOML in Clojure, you need a library like clj-toml. First, add it to your deps.edn:

{:deps {clj-toml {:mvn/version "0.5.0"}}}

Then parse some TOML:

(require '[clj-toml.core :as toml])

(def config-str "title = 'TOML Example'")

(def parsed-config (toml/parse-string config-str))

;; Get the title from the parsed TOML
(println (:title parsed-config)) ;; Output: TOML Example

To generate TOML:

(def data {:title "TOML Example"})

(println (toml/generate-string data))
;; Output: title = "TOML Example"

Deep Dive

TOML was created around 2013 by Tom Preston-Werner, co-founder of GitHub, as a simpler alternative to YAML and JSON for config files. It aims for clarity and intends to be a spec humans can read without additional tools.

While JSON is often used for APIs and web apps, and YAML can get complex with references and script abilities, TOML stands out with a focus on simple, table-based structures. This simplicity makes it especially popular in the Rust community and other modern language environments.

Clojure, with its focus on simplicity and practicality, pairs well with TOML for config. clj-toml or alternative libraries bridge the gap. They translate TOML’s static data into Clojure’s dynamic, functional world.

See Also