You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
apologies if this is not the right place to ask for enhancement requests. since python3.13 added support for colorization in repl, i was wondering if some basic colorization could be added for the python's cli json tool? jq[0] does this, the keys are bolded and have a different color from the values.
if this gets implemented i think a lot of people will be happy to just use python and not have to install yet another library to fulfill their needs :-)
@nineteendo thank you for taking the time to look into it. couple of notes: 1) unlike jq and python's json tool, i see your solution is not recursive (objects and arrays inside a json object are not nicely displayed, but everything is in one line) 2) i'm not a fan of that shade of bright blue
Activity
ZeroIntensity commentedon Mar 31, 2025
cc @hugovk
sobolevn commentedon Apr 1, 2025
I think that adding colors by default can possibly break piping on some shells / systems. But, I am not 100% sure.
Like
get_json | python -m json.tool | expects_json_texthugovk commentedon Apr 1, 2025
By default, the
_colorizemodule does check if we're in a tty before enabling colour:cpython/Lib/_colorize.py
Lines 109 to 112 in 3b3720f
Compare the output of
python3.14 -m calendarandpython3.14 -m calendar | catZeroIntensity commentedon Apr 1, 2025
Speaking of which, is that extra highlighted space before the
1supposed to be there?The assymetry looks a little funky to me.
Eclips4 commentedon Apr 1, 2025
I guess so. At least so-called cal does the same:
srinivasreddy commentedon Apr 2, 2025
asymmetry happens on MacOS too.
hugovk commentedon Apr 2, 2025
The highlight includes the unprinted 0 prefix.
nineteendo commentedon Apr 2, 2025
Like this?
raztd commentedon Apr 6, 2025
@nineteendo thank you for taking the time to look into it. couple of notes: 1) unlike jq and python's json tool, i see your solution is not recursive (objects and arrays inside a json object are not nicely displayed, but everything is in one line) 2) i'm not a fan of that shade of bright blue
nineteendo commentedon Apr 6, 2025
That's because
-L1sets--maximum-indent-levelto 1.I'm using the same colours as jq, this is just how Powershell renders them.
[-]colorization in cli json tool[/-][+]Color in json.tool CLI[/+]gh-131952: Add colour to the ``json`` module CLI (#132126)