Refactored json serializer