Reading and updating values inside EDN files.
Edits are spliced into the file's text, so comments, key order and hand
formatting survive - see jj.bettong.impl.edn-text. Pass
{:preserve-formatting? false} to rewrite the file from its data instead,
which is pretty-printed and loses comments.
Reading and updating values inside EDN files.
Edits are spliced into the file's text, so comments, key order and hand
formatting survive - see `jj.bettong.impl.edn-text`. Pass
{:preserve-formatting? false} to rewrite the file from its data instead,
which is pretty-printed and loses comments.(delete-edn opts {:keys [path key_path]})(delete-in-file! file path)(delete-in-file! file
path
{:keys [preserve-formatting?] :or {preserve-formatting? true}})Removes the key at path, leaving the formatting around it alone.
Returns the file's new data.
Removes the key at `path`, leaving the formatting around it alone. Returns the file's new data.
(get-in-file file path)The value at path, or nil. An empty path returns the whole file.
The value at `path`, or nil. An empty path returns the whole file.
(parse-key k)A path element arrives as text. It is read as EDN, so ":server" is the keyword :server, "0" is the index 0, and ""name"" is the string "name". Anything unreadable is kept as a plain string key.
A path element arrives as text. It is read as EDN, so ":server" is the keyword :server, "0" is the index 0, and "\"name\"" is the string "name". Anything unreadable is kept as a plain string key.
(parse-path path)(parse-value value)The new value, read as EDN so it can be any shape - a number, a string, a keyword, a map, a vector.
The new value, read as EDN so it can be any shape - a number, a string, a keyword, a map, a vector.
(read-edn opts {:keys [path key_path]})(set-edn opts {:keys [path key_path value]})(set-in-file! file path value)(set-in-file! file
path
value
{:keys [preserve-formatting?] :or {preserve-formatting? true}})Sets path to value, creating intermediate maps as needed.
Returns the file's new data.
The edit is spliced into the file's text, so everything around it - comments included - is left exactly as it was. With {:preserve-formatting? false} the file is rewritten from its data and pretty-printed instead.
Sets `path` to `value`, creating intermediate maps as needed.
Returns the file's new data.
The edit is spliced into the file's text, so everything around it - comments
included - is left exactly as it was. With {:preserve-formatting? false} the
file is rewritten from its data and pretty-printed instead.(update-in-file! file path f & args)Applies f to the value at path - the Clojure-side counterpart to
set-in-file!, for when the new value depends on the old one.
(update-in-file! "config.edn" [:server :port] inc)
Applies `f` to the value at `path` - the Clojure-side counterpart to set-in-file!, for when the new value depends on the old one. (update-in-file! "config.edn" [:server :port] inc)
(write-file! file data)Writes data back, pretty-printed so the file stays readable.
Writes `data` back, pretty-printed so the file stays readable.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |