Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Created April 16, 2020 13:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackrusher/e628abb653429c22bc6330752b3e49a5 to your computer and use it in GitHub Desktop.
Save jackrusher/e628abb653429c22bc6330752b3e49a5 to your computer and use it in GitHub Desktop.
Convert the current region in emacs from JSON to EDN using Bork's Jet.
;; Uses https://github.com/borkdude/jet
;; 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 ()
(interactive)
(shell-command-on-region (region-beginning)
(region-end)
"jet --pretty --keywordize keyword --from json --to edn"
(current-buffer)
t))
@vedang
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."
  (interactive)
  (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"))))

@jimmy-alvarez
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