Mike Conigliaro

Jazor: A Simple Command Line JSON Parsing Tool

Tools like cURL and Wget are great for basic troubleshooting of REST interfaces, but what if you’re only interested in a small subset of the JSON returned from a REST call? If you have a REST interface that returns tens or hundreds of lines of output, it can be a pain to find the values you’re looking for. Sure you could pipe the output to a complicated multi-line grep command, but wouldn’t it be nice if there was a command line tool that allowed you to drill down into a JSON object and only show you the values you’re interested in? I thought so too, but I got tired of waiting for someone else to write it for me.

Jazor (rhymes with “razor”) arose from my desire for a better REST testing tool, as well as my need to create health check scripts for several web services that provide health URLS with JSON output. Rather than write (nearly) the same script over and over, I thought it would be handy to be able to do something like this:

jazor http://example.com/health requests.POST.errors.errorCount

The first parameter is the health URL and the 2nd parameter is the JSON object I’m interested in. If I can pull out individual values like this, it becomes trivial to write simple shell scripts to monitor these values. But it gets better:

jazor http://example.com/health -t 'requests.POST.errors.errorCount == 0'

Using the -t option, I can have Jazor do the testing for me. I can specify as many tests as I want (by using the -t option multiple times), and if any of them fail, Jazor will exit with a non-zero status code. This means Jazor can act as both a testing tool and a simple monitoring script.

blog comments powered by Disqus