Implement JSONEncoder. Fixes #117.

Hi @GraylinKim

Please could you provide feedback on this pull request, let me know if it's in line with your thinking and what is still necessary to do? 

Let me know if there are things missing from the JSONEncoder, or what kind of testing is possible and required?

Thanks!