json-emacs / json-mode

Major mode for editing JSON files with emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

beautify-json fails on Windows

phatcabbage opened this issue · comments

Windows command prompt (cmd.exe) doesn't treat a single quote as an escape character, so when beautify-json calls

(shell-command-on-region b e
  "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\")'" (current-buffer) t)))

the command errors out (replacing the buffer text in the process, as per issue #2).
By changing around the quoting format, I have gotten it working on my Windows 7 machine, but I don't have access to any Linux/BSD/Mac/etc machines to test on (though I believe it should work just fine). Here's my rendition:

(shell-command-on-region b e
"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')\"" (current-buffer) t)))

Hey @phatcabbage can you please check what version you're using? This may have already been resolved, looking at https://github.com/joshwnj/json-mode/blob/master/json-mode.el

@phatcabbage in the latest version we are using json-reformat to do json pretty-printing, instead of shell command to python (#20). Can you please check whether the issue in windows is resolved now, and we'll re-open it if so.