2vnxaw
Last Updated: February 25, 2016
·
4.236K
· 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.

Say Thanks
Respond

3 Responses
Add your response

5736
85f6b7b520ac6a659f61583ce918704e

it relies on python ...

over 1 year ago ·
5897
8519a654e3b51ef7dd19486a859ca91c

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

over 1 year ago ·
5901
85f6b7b520ac6a659f61583ce918704e

@gongo thank u very much

over 1 year ago ·