json - Emacs 模式编辑 JSON

有人知道编辑 JSON 的良好 Emacs 模式吗?我正在开发的一个应用程序使用基于 JSON 的通信协议(protocol),并且将数据很好地缩进和语法高亮将在我弄清楚它的过程中帮助我很多。

最佳答案

+1 乔希的 json-mode ——对我来说效果很好。我加了

(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 -m json.tool" (current-buffer) t)))

(define-key json-mode-map (kbd "C-c C-f") 'beautify-json)

到 json-mode.el 以使 shell 命令调用更容易。

更新:对于那些需要/希望使用 unicode 执行此操作的人,请参阅我的问题 here .结果是而不是使用:

python -m json.tool

你会想要使用

python -c 'import sys,json; data=json.loads(sys.stdin.read()); print json.dumps(data,sort_keys=True,indent=4).decode("unicode_escape").encode("utf8","replace")'

这既美化了 JSON,又保留了原始的 Unicode 内容。

https://stackoverflow.com/questions/435847/

相关文章:

javascript - 如何通过 Ajax 请求将 Select2 与 JSON 一起使用?

json - Postgres : How to convert a json string to

python - 如何在 Django 中不使用模板返回 JSON?

jquery - jQuery 1.4.1 中缺少 JSON 字符串化?

c# - 使用 JObject 即时创建 JSON

python - 不是 JSON 可序列化的

json - 将 Go map 转换为 json

c# - 从 HTTPClient 响应中解压 GZip 流

javascript - JSON 安全最佳实践?

xml - json和xml有什么区别