JSON REST API response with empty list

I'm producing a REST API with JSON response. In case the response is emtpy, the consumers like to get the following response:

{

  "data": []

}

All I get when I try to create the above response is:
{
    "data": [
        ""
    ]
}

Is it possible to get rid of the empty text "" (the default value for a text field) in de response?

The option 'Send default values' from the REST API is set to No. 


How are you testing the API? Are you using any specific tools like Postman, Boomerang, etc., or are you just testing from within Service Studio?

Hi Pauline,

If you get "data":[""], that means that data is a Text List with a single element, which consists of an empty string. So there's like a problem with your code, always adding an element.

Thanks for your replies!


@Hanno, I use Postman to test the API.


@Kilian, that's the point. Outsystems always shows the default value, even when the option 'Send default value' is set to No. An empty list is not really empyt, it always had the default values (for a string "", for a number 0 etc) So far I know, I can't change that. So I hope anyone in this forum does have a solution for my issue.

Hi Pauline,

What I'm saying is I don't think your empty List is actually empty. Did you debug to see whether it truely is empty? I'm asking because the behaviour you show is not something I've seen before.

Killian is correct.

I was able to generate your expected response here: 

https://hannojs.outsystemscloud.com/REST_API/rest/RESTAPI1_Expose/RESTAPIMethod2

by simply not setting my list to anything.

This API returns a Text List.

All settings are as you set out in your original post.

@Hanno, I see your result and that looks good. But what do you mean by 'by simply not setting my list to anything'?


Solution

Pauline, I am not setting the Output parameter on the REST API.

Can you perhaps share a screenshot of the REST API Action or perhaps the .oml file?

Solution

Yes, that's it! Simple it is. Thanks.