Refactoring the JSON-related code.