This is identical to the original implementation of `#to_json` in the JSON library; however, I re-implement it here to ensure that this version gets called, rather than a potentially monkey patched version in `Time`