Test JSON encoding and fix related bugs.  Fixes #12.