Skip to content

Instantly share code, notes, and snippets.

@wesm
Created April 27, 2014 05:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesm/11338078 to your computer and use it in GitHub Desktop.
Save wesm/11338078 to your computer and use it in GitHub Desktop.
Format JSON nicely in Emacs
(defun node-format ()
(interactive)
(save-excursion
(shell-command-on-region (mark) (point) "node -e \"process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function (chunk) { eval('foo = ' + chunk); console.log(JSON.stringify(foo, null, 2));});\"" (buffer-name) t)
)
)
(global-set-key "\C-c\C-j" 'node-format)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment