0
我正在處理具有單行JSON字符串列表的文件。要編輯單個json對象,我找到了這個工具:https://github.com/gongo/json-reformat。現在,我正在尋找反向操作:給定一個格式良好的Json對象,將其摺疊爲一個單獨的字符串。Emacs程序將Json摺疊爲單行
Emacs的版本:24.5.1
我正在處理具有單行JSON字符串列表的文件。要編輯單個json對象,我找到了這個工具:https://github.com/gongo/json-reformat。現在,我正在尋找反向操作:給定一個格式良好的Json對象,將其摺疊爲一個單獨的字符串。Emacs程序將Json摺疊爲單行
Emacs的版本:24.5.1
看起來不像json-reformat
帶有任何東西了點。
這裏是一個互動的功能,可以這樣做:
(defun json-to-single-line (beg end)
"Collapse prettified json in region between BEG and END to a single line"
(interactive "r")
(if (use-region-p)
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(while (re-search-forward "\\s-+" nil t)
(replace-match " "))))
(print "This function operates on a region")))
只是評價函數定義 - >突出JSON片斷你想重新格式化 - >和調用這個函數交互
真棒,謝謝!我把它放在我的.emacs文件中。 – alexgbelov