Refactored JSON string generation