Added a few more unit test for json and improved the error handling.