-
-
Save chales/510c5bed59a32ed0cb55 to your computer and use it in GitHub Desktop.
2016/03/15 | |
Tested with BBEdit 11.5 / OS X 10.11.3 / Python 2.7.10 | |
http://grokin.gs/blog/elegant-json-pretty-print-for-bbedit/ | |
Place the script (or a link to this script) in the ~/Library/Application Support/BBEdit/Text Filters directory | |
Restart BBEdit. | |
The new filter should be under: "Test > Apply Text Filter > bbedit-pretty-json" |
#!/bin/bash | |
python -c "import sys, json; print json.dumps(json.load(sys.stdin), indent=2)" |
Environment: macOS Sonoma 14.5 (23F79) BBEdit version 15.0.3 (15A102, 64-bit Intel)
Using the current version some UTF-8 characters are returned encoded: in: "forsøg" out: "fors\u00f8g"
I have verified, that the BBEdit document is in fact using UTF-8 encoding. Any clues?
Solved: add ", ensure_ascii=False" to the json.dumps command:
#!/bin/bash
python3 -c "import sys, json; print (json.dumps(json.load(sys.stdin), indent=2, ensure_ascii=False))"
I concur with @michaldobisek in that jq is a much more elegant way to go, especially since python is no longer installed on macOS with the developer tools.
I've updated the gist I maintain with this approach: https://gist.github.com/levigroker/3777091
Thank you very much, solves a problem!
I had to tweak the script slightly (*am on MacOS Sequoia if that makes a difference)
#!/bin/bash
python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin), indent=2))"
but then the jq
worked too as-is.
As of BBEdit 14.0, rather than this custom filter, you can use BBEdit's own built-in module.
Added JSON formatting support to the factory-supplied JSON language module. Choose "Reformat Document" from the Text menu to reformat the document's text.
Choose "Reformat Document" from the Text menu to reformat the document's text.
https://www.barebones.com/support/bbedit/notes-14.0.html
Aaah, at last. Bliss!
Thanks for the hint. I updated and it works perfectly. :-)
Environment:
macOS Sonoma 14.5 (23F79)
BBEdit version 15.0.3 (15A102, 64-bit Intel)
Using the current version some UTF-8 characters are returned encoded:
in: "forsøg"
out: "fors\u00f8g"
I have verified, that the BBEdit document is in fact using UTF-8 encoding. Any clues?