Convert for using .to_json

This will support additional cases of encoding, like where the expected result only is a single object (like a string).

Compared to what other implementations does (like .to_json, JSON.dump, JavaScript's JSON.stringify), it seems to be acceptable to do it this way.

However, not been able to locate the RFCs - at the time of writing - specifying what is right or wrong, but would be nice to have confirmed or declined.