Fix all tests, bugs and leaks related to json