Created
March 21, 2013 14:29
-
-
Save drocamor/5213443 to your computer and use it in GitHub Desktop.
A function to use json.tool to beautify JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; beautify json | |
(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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To avoid trailing white spaces on lines whose last character is e.g. a comma, maybe the last line of code can be changed as follows:
This pipes mjson.tool's output into `sed' to remove white spaces at the end of lines.