[ardoJSON] Problems with JSON mapping

[ardoJSON] Problems with JSON mapping

  
Forge Component
(22)
Published on 24 Oct (4 weeks ago) by Ricardo Silva
22 votes
Published on 24 Oct (4 weeks ago) by Ricardo Silva

Hi,

I am having difficulties trying to consume a REST service with the following JSON as the result (example):

{
  "result": [
    [
        {
            "division": "K",
            "company": "A"
        },
        {
            "division": "L",
            "company": "B"
        },
        {
            "division": "M",
            "company": "C"
        }      
    ],
    {
        "succeeded": true,
        "statusCode": 200,
        "message": "A message."
    }
  ]
}


Is there any way to do this properly in Outsystems? The platform is unable to map the JSON automatically and I am having no luck trying to do it manually.

Can this be done?

Kind regards,

Bart.


Solution

Well, that's a weird one.

If you look at it you'll see that the result list has two items, one list of division + company objects and one object with the success status and stuff.

lists of heterogenous stuff are not possible to map into the OutSystems type system.


Is it always like this? the first item a list and the second an object? If so you can use ardoJSON's JSONSelect to fetch the items and process them seperately. This can be done by recreating the JSON into a more manageable structure, for example:


{

  "resultList": JSONSelect(original, "result[0]")

  "resultStatus": JSONSelect(original, "result[1]")

}

Solution

Thanks Ricardo. It is indeed a bit unusual.

I will give your suggestion a go. If it's too much effort I will ask the supplier of the service to change the output to a more manageable form.

At least now I have confirmation that this is not that easy to process in a few simple steps.