1

Im making a POST to an endpoint and this is what I get back in my response, its a successful POST and the status is 200 but the payload is empty.

{
  "payload":[],
  "datetimestamp":"2023-03-23_01:26:45"
}

storing it in a string and making a map

String strJSON = response.getBody();
Map < String, Object > fullMap = ( Map < String, Object > )JSON.deserializeUntyped( strJSON );

now when I debug this:

System.debug('fullmap payload-->' + fullMap.get('payload'));

I get back this : fullmap payload-->()

how can i validate that this is empty? I tried the following

Object obj2 = fullMap.get('payload');
    if(obj2 == '()'){
        System.debug('hi');
    }

Basically I want to know when the payload is empty, so I can have logic there.

1 Answer 1

0

I think you should use

if(obj2 == null) {

    System.debug('Payload is null.');
}

OR

if(obj2.isEmpty()){
    System.debug('Payload is empty');
    
}

OR

if(obj2.size() == 0){
    System.debug('Payload is empty');
    
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .