|# A text filter for BBEdit. If it encounters a JSON error, it writes an error message|
|# to stderr (appears in a new BBEdit window) and leaves the original text unaltered.|
|# c.f. http://crisp.tumblr.com/post/2574967567/json-pretty-print-formatting-in-bbedit|
|# c.f. http://blog.scottlowe.org/2013/11/11/making-json-output-more-readable-with-bbedit/|
|input = sys.stdin.read()|
|obj = json.loads(input)|
|except Exception as e:|
|sys.stderr.write("Error reading JSON: %s" % str(e))|
|json.dump(obj, sys.stdout, ensure_ascii=True, indent=2)|
|if __name__ == '__main__':|
I see that you had that in the past. So it was removed intentionally... but I don't understand why.
I guess I could post my variation somewhere else... but I'm looking for any comments about whether adding "ast" has drawbacks and why you changed that first line.
@mdahlman Glad this helped you. You're right about the shebang line being messed up. That must have been an inadvertent change made during my last commit. Technically, JSON only supports double quotes. Loading the ast module feels pretty heavy-weight to me; I would probably do a character substitution instead. But I don't run into files like that, so YMMV.
Support unicode character output, instead of \u6690
Same problem (Third one) with @mdahlman. Again solved with ast:
Slight update and targets Python 3 (since 2 is now EOL and built-in Python 2 on Big Sur warns to use Python 3 instead):