This is really nice.  I could have done something like this code for making sql2o support JSON in general.. instead I built it into the project.  Good to know that it's pretty straightforward to add a custom type/enum.