Last Updated: December 26, 2018
·
8.667K
· st3fan

Beautify JSON in Emacs

Not completely sure where I found this, but I've had this in my .emacs for a while now:

(defun beautify-json ()
  (interactive)
  (let ((b (if mark-active (min (point) (mark)) (point-min)))
        (e (if mark-active (max (point) (mark)) (point-max))))
    (shell-command-on-region b e
     "python -mjson.tool" (current-buffer) t)))

Just run M-x beautify-json on a buffer and it will reformat it.

3 Responses
Add your response

it relies on python ...

over 1 year ago ·

@cnwggu Pure emacs lisp version -> https://coderwall.com/p/w3qvba

over 1 year ago ·

@gongo thank u very much

over 1 year ago ·