Stefan Arentz

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.

emacs