Rename toJSON transform function

This makes it clearer that the toJSON method isn't solely responsible
for doing the JSON transformation.