Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2020 13:26
What would you like to do?
Convert the current region in emacs from JSON to EDN using Bork's Jet.
;; Uses
;; On OSX, install jet with:
;; brew install borkdude/brew/jet
;; I invoke this with M-x, you might want to bind it to a key
(defun json->edn ()
(shell-command-on-region (region-beginning)
"jet --pretty --keywordize keyword --from json --to edn"
Copy link

vedang commented Aug 29, 2022

Tweaked it a bit into the following:

(defun json->edn ()
  "Convert the selected region, or entire file, from JSON to EDN."
  (let ((b (if mark-active (region-beginning) (point-min)))
        (e (if mark-active (region-end) (point-max)))
        (jet (when (executable-find "jet")
               "jet --pretty --keywordize keyword --from json --to edn")))
    (if jet
      (let ((p (point)))
        (shell-command-on-region b e jet (current-buffer) t)
        (goto-char p))
      (user-error "Could not find jet installed"))))

Copy link

How can I install this function in my emacs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment