Testing JSON grammars

Perl 6 grammars make it easy to parse JSON and it’s a favorite example to show off the feature. This post is about testing the grammar; you don’t need another example here. I list several at the end of this post.

I went looking for some sort of official test corpus to throw at parsers. Googling gave me some internal links to json.org for a tool called JSON_Checker that has some test files. As I created my own JSON grammar (which looks just like all the examples I list at the end of this post, really), I used JSON_Checker files as the tests. I fixed some tests and put my versions in it my json-acceptance-tests GitHub repo.

Here’s the output, which I’ve labeled nicely with Terminal::ANSIColor. Those failures aren’t real. One doesn’t believe that anything other than an object or array can be a top-level value and the other thinks you should stop parsing at a certain depth.