Add JSON encoder and tests for write module.