JSON serialization code refactoring