Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



30 Commits

Repository files navigation

Deep Environmental Configuration


Build Status Clojars Project codecov

dec builds arbitrarily nested data structures from simple KV strings.

  • Tiny codebase; tiny name
  • Functionally pure
  • Composable
  • Zero runtime dependencies
  • 100% test coverage with unit tests & test.check
  • Fully linted against eastwood & kibit
  • Up-to-date Change Log


Env vars are constrained to simple key value pairs, yet they are ubiquitous. Docker config and 12 Factor Config in particular rely on this traditional mechanism. But modern apps often require more complex data structures, to wit: maps and lists.


dec exposes two primary functions: explode and enflat. They are inverses of eachother, such that identity == (comp explode enflat), i.e.:

(let [nested {:foo {:bar [:baz :qux]}}]
  (= nested (explode (enflat nested))))
;;=> true

Assume our env looks like:

export DEC_LEVEL=debug

Then we we obtain some env vars via environ, as one does, filter by a known prefix, and explode the results:

  '[environ.core :refer [env]]
  '[dec :refer [explode]])

(explode (into {} (filter (fn [[k v]] (.startsWith (name k) "dec")) env)))

{:dec {:hosts ["" ""], :level "debug"}}

A little simpler, without the env:

  {:dec-level "debug"
   :dec-hosts-0 ""
   :dec-hosts-1 ""})

{:dec {:hosts ["" ""], :level "debug"}}

Environ is not required, nor is it a dependency of dec; I'm using it as an example of a common way to obtain environmental configuration.

Custom delimiter

dec optionally takes a delimiter parameter:

(explode {:dec.hosts.0 ""
          :dec.hosts.1 ""
          :dec.level "debug"}
          {:delimiter "."})

{:dec {:hosts ["" ""], :level "debug"}}

Run tests

lein test

Calculate code coverage

lein cloverage

Run linters

lein kibit
lein eastwood


Copyright © 2016 Trevor C. Hartman

Distributed under the Eclipse Public License either version 1.0 or any later version.