Refactored json parsing code