JSON REST API response with empty list
Question

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. 


mvp_badge
MVP
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?

Can you please share the solution. I am also having a exact same problem.

or you can post the same on my question

https://www.outsystems.com/forums/discussion/72911/json-structure/

mvp_badge
MVP

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?

mvp_badge
MVP

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.

mvp_badge
MVP

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.

mvp_badge
MVP

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'?


mvp_badge
MVP
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?

Can you please share the solution. I am also having a exact same problem.

or you can post the same on my question

https://www.outsystems.com/forums/discussion/72911/json-structure/

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


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.