Add json functionality and refactored test cases.