Fix JSON encoding issues

Moved over JSON encoding work to use a library. Updated associated tests.