jsoncolor
2021-09-15
One of the benefits of using jq is that it colorizes & prettifies
JSON output, making it much easier to parse visually. I wanted to do the same for sq
,
which is written in Go. Looking around the existing libraries landscape, I found
several colorizing encoders, but each had shortcomings.
nwidger/jsoncolor
does the trick, but performance is egregious, due to it performing a re-parsing step.hokaccha/go-prettyjson
andTylerBrock/colorjson
both colorize, but neither provide a stdlib-compatibleEncoder
implementation.
So, I created neilotoole/jsoncolor
, which ticks all
the boxes. It’s fast (faster than stdlib in many cases), configurable, and is a drop-in replacement
for the stdlib json
package. I’ve already been using it in CLIs on client projects, and it works well.
Colorization is configurable. This is the color scheme I chose for sq
, mimicking jq’s color palette.