json-pretty-print-buffer delete the content of a JSON file
rememberYou opened this issue · comments
Hey,
I'm using GNU Emacs 28.0.50 and when I use the json-pretty-print-buffer
function in a JSON file, the content of the file are removed with "Expecting value" as a message.
My configuration:
(use-package json-mode
:delight "J "
:mode "\\.json\\'"
:hook (before-save . my/json-mode-before-save-hook)
:preface
(defun my/json-mode-before-save-hook ()
(when (eq major-mode 'json-mode)
(json-pretty-print-buffer)))
(defun my/json-array-of-numbers-on-one-line (encode array)
"Prints the arrays of numbers in one line."
(let* ((json-encoding-pretty-print
(and json-encoding-pretty-print
(not (loop for x across array always (numberp x)))))
(json-encoding-separator (if json-encoding-pretty-print "," ", ")))
(funcall encode array)))
:config (advice-add 'json-encode-array :around #'my/json-array-of-numbers-on-one-line))
Do you have any idea what the problem is?
Thank you for your work.
json-pretty-print-buffer
is a function of json.el
. Please contact them.
https://github.com/emacs-mirror/emacs/blob/207cd4c23570dc1cb1fdb57a70c67a3be5cefe33/lisp/json.el#L780