Can someone suggest how I can beautify JSON in Python or through the command line?
The only online based JSON beautifier which could do it was: http://jsonviewer.stack.h
A minimal in-python solution that colors json data supplied via the command line:
import sys
import json
from pygments import highlight, lexers, formatters
formatted_json = json.dumps(json.loads(sys.argv[1]), indent=4)
colorful_json = highlight(unicode(formatted_json, 'UTF-8'), lexers.JsonLexer(), formatters.TerminalFormatter())
print(colorful_json)
Inspired by pjson
mentioned above. This code needs pygments
to be installed.
Output example: