Hello,
I have the following JSON structure returned by a REST API. The issue I'm facing is that under ApprovalSettings attribute sometimes I receive a simple object, sometimes an array which cannot be correctly mapped to an OutSystems structure (the JSON is dynamic).
I am wondering what is the easiest way to extract only the relevant information? I changed the response to a Plain Text and tried using ardoJSON's JSON_Listify() action, but I cannot seem to get the result I want. Maybe there are some other ways of achieving this.
The only information relevant for me is the UserID attribute.
Regards,
Bogdan
{
"Users": [
"ExternalID": "string",
"ClientID": 0,
"ClientName": "string",
"GroupID": 0,
"PartnerID": 0,
"Username": "string",
"Status": "string",
"StatusReason": "string",
"Expire": "2023-03-27T16:08:31.656Z",
"Created": "2023-03-27T16:08:31.656Z",
"GroupName": "string",
"PartnerName": "string",
"LifetimeCampaigns": 0,
"LifetimeEmails": 0,
"UserID": 0,
"Role": "string",
"RoleID": 0,
"FirstName": "string",
"LastName": "string",
"Email": "string",
"PasswordChange": "2023-03-27T16:08:31.656Z",
"LastLogin": "2023-03-27T16:08:31.656Z",
"Last12MonthsCampaigns": 0,
"Last12MonthsEmails": 0,
"Last30DaysCampaigns": 0,
"Last30DaysEmails": 0,
"Last30DaysEmailAverage": 0,
"Last30DaysEmailChange": 0,
"Last30DaysCampaignsChange": 0,
"Last30DaysCampaignsAverage": 0,
"SubscriptionEstimatedUsage": 0,
"SubscriptionEstimatedDifference": 0,
"SubscriptionSettings": [
{}
],
"ApprovalSettings": [
]
}
"ResultCode": 0,
"ResultDescription": "string",
"TotalResults": 0
Hi @Bogdan Boglea ,
just checking if I get this right : OS has problems because ApprovalSettings has a different structure on different calls. And as a consequence, you sometimes run into parse errors.
But you are not interested in anything that can be found inside ApprovalSettings ?
In that case, just avoid it getting parsed, as any information in the JSON OS is not looking for, is ignored and structure changes are harmless.
You can do one of these 2 things, after first adding the consumed REST api with full structure (so no need to make response a plain text) :
Or you could avoid OS ever even making any structures for this, by editing it out of the example response before doing 'copy to response body'.
Be sure to document this well, as anybody working on that REST api in the future will want to know about this.
Dorine
Hi Dorine,
Amazing, not sure why I didn't think of this, I remember trying to remove some attributes from the response structure but encountered some issues.
Now with a clear mind I just removed the ApprovalSettings structure and it seems the API works as expected.
Thanks a lot,
Hi
I did quick page where you can test your json.If it's what you expected I send you this example.
My Page: https://cesar-mateus.outsystemscloud.com/WebAppsTests/TestJSON?_ts=638155395786049590
TESTED JSON
"UserID": 105,
},
"UserID": 101,
Hi Cesar,
Seems it works for your example, could you maybe provide the OML so I can also try it out with some real data and see the implementation?
Sure I'll upload here
I think not needed anymore, but thanks for your efforts.
Dorine's idea did the job :D
Great! BogdanAlways can count with us 🙂