Kinbiko

Go: jsonassert - A test utility for comparing and verifying JSON

February 06, 2019

Some technical knowledge assumed.

Today I released v1.0.0 of a Go package called jsonassert. It is my first self-motivated open source contribution that I think has a chance of being useful to someone other than just myself. Okay, that’s not quite true but it’s the first one I’ve written in Go.

I realised the need for this package when attempting to increase the test confidence of a relatively untested package that sends JSON to a server. There was no easy way of making assertions against this JSON body, at least not without moving to an entirely new test framework. I’m a big fan of the testing package in the Go standard library, and this was already being used elsewhere in the package I was working with. So I settled for writing more lines of code than I would have liked, attempting to parse the JSON nested-object-by-nested-object as deserialising into a struct would defeat the purpose of the test.

However, when doing slogging away at these SLOCs I kept being haunted by an urge to write this jsonassert package. At the beginning of this year, I announced that my new years resolution would be to do more uncomfortable things. Well, one of those uncomfortable things was to stream myself programming on Twitch, which I have done several times now (I bet you can’t figure out how to hit that ‘follow’ button!). The thing I’ve been streaming the most has been the development of this package, essentially from scratch. Now that it’s released in what I believe to be in a production-ready state, I need to figure out what else I can hack on… Maybe a little tool that can help me study Japanese? We’ll see!

Watch this space my Twitch streams!


Roger Guldbrandsen

Written by Roger Guldbrandsen.