#!/usr/bin/env python"""Convert JSON data to human-readable form.
(Reads from stdin and writes to stdout)"""
import systry:import simplejson as jsonexcept:import json
print json.dumps(json.loads(sys.stdin.read()), indent=4)sys.exit(0)
function bench {time (for i in {1..1000}; doecho '{ "foo" : { "bar": { "dolorem" : "ipsum", "quia" : { "dolor" : "sit"} } } }' \| $@ > /dev/nulldone)}
这是我的mac上的结果(32 GB,Apple M1 Max,YMMV):
bench python -m json.tool# 8.39s user 12.31s system 42% cpu 48.536 totalbench jq# 13.12s user 1.28s system 87% cpu 16.535 totalbench bat -p -l json # NOTE: only syntax colorisation.# 1.87s user 1.47s system 66% cpu 5.024 totalbench jj -p# 1.94s user 2.44s system 57% cpu 7.591 totalbench xidel -s - -e '$json' --printed-json-format=pretty# 4.32s user 1.89s system 76% cpu 8.101 total
# this in your bash profilejsonprettify() {curl -Ss -X POST -H "Content-Type: text/plain" --data-binary @- https://jsonprettify.vercel.app/api/server?indent=$@}
{"time":"2021-06-09T02:50:22Z","level":"info","message":"Log for pretty JSON","module":"init","hostip":"192.168.0.138","pid":123}
{"time":"2021-06-09T03:27:43Z","level":"warn","message":"Here is warning message","module":"send-message","hostip":"192.168.0.138","pid":123}