Fixed small bug and refactored expect_json_impl