Emacs mode to edit JSON

后端 未结 12 1744
面向向阳花
面向向阳花 2021-01-30 12:15

Does anybody know a good Emacs mode to edit JSON? An app I am working on uses a JSON based communication protocol and having the data nicely indented and syntax-highlighted woul

相关标签:
12条回答
  • 2021-01-30 12:50

    js3-mode:https://github.com/thomblake/js3-mode

    js3-mode is an improved js2-mode

    This package can be installed by package-list-packages command

    0 讨论(0)
  • 2021-01-30 12:50

    I will also second Josh's json-mode, but also recommend flymake-json as an addition. It helps highlight syntax errors.

    I don't like using python -mjson.tool because it reorders items in JSON objects. I find (prog-indent-sexp) works just fine to reindent, and using jsonlint instead of python -mjson.tool works for pretty printing/reformatting in beautify-json

    (eval-after-load "json-mode"
      '(progn
         (require 'flymake-json)
         ;; flymake-cursor displays error in minibuffer message area instead of requiring hover
         (require 'flymake-cursor)
    
         (add-hook 'json-mode-hook 'flymake-json-load)
         (define-key json-mode-map "\C-c\C-n" (function flymake-goto-next-error))
      )
    )
    
    0 讨论(0)
  • JSON is supported by espresso-mode

    0 讨论(0)
  • 2021-01-30 12:56

    Have you tried Steve Yegge's js2-mode for Emacs?

    0 讨论(0)
  • 2021-01-30 12:56

    I've prepared a workaround for js2-mode so it parses json files without errors. You can find it in my comment: http://code.google.com/p/js2-mode/issues/detail?id=50#c7

    (I wanted to post it as a comment do J.F. Sebastian solution, but it seems I'm not allowed to do so (no 'add comment' link))

    0 讨论(0)
  • 2021-01-30 12:59

    If you want something lightweight try this major-mode I hacked together: https://github.com/joshwnj/json-mode

    It's actually no more than some extra syntax highlighting on top of javascript-mode, but for my purposes I've found it to work quite well.

    Another common use-case is auto-formatting a JSON file (eg. if it's whitespace-compressed and you want more readability). To do this I'm just piping the buffer through a command-line script: C-u M-|

    0 讨论(0)
提交回复
热议问题