jp 0.2

Paul Hammond, 8 March 2014

Version 0.2 of jp is out. It fixes a small bug where significant whitespace was removed from invalid JSON documents. More importantly it also adds some color to the output:

screenshot of jp output

Color didn’t make it into the first version of jp, but it was one of the reasons I built a new parser when I started writing the code. Adding ANSI Escape codes to one of the many existing general-purpose JSON libraries would be possible, but I’m not convinced it would be the right thing to do. Most JSON code is now part of the core library for any language and adding extra code to every JSON generating application to handle this one specific use case is a waste of CPU and future developer debugging time. Even if a patch were appropriate, it would take a really long time before I could rely on the functionality being on a system, so I wrote a new library for this use case.

In general it’s hard to argue against code reuse as a concept; none of the computers systems we use today would be possible without it. But sometimes we take that concept too far, and try to reuse code in a context it wasn’t designed for, or write code to handle every use case when just one is needed.

Greg Wilson’s “What We Actually Know About Software Development” is, in my view, one of the best presentations ever given about code. If you haven’t watched it, you should. Around 32 minutes in he talks about some research from Boeing that suggests “if you have to rewrite more than about a quarter of a software component, you’re actually better off rewriting it from scratch”. This seems like a small but useful example of that effect in action.

But I digress. If you want your JSON in color you should get the latest jp.