Refactored toJsonNode() method