Problem accessing JSON data from Web Services Data Actions

Hi everyone, I got this response from an endpoint I cosumed using web services data actions:

Normal Output

{
    "myList": [
        {
            "id": 1,
            "texto": "Texto dto 1",
            "data": [
                "lion",
                "tiger",
                "dog"
            ]
        },
        {
            "id": 2,
            "texto": "Texto dto 2",
            "data": [
                "lion2",
                "tiger2",
                "dog2"
            ]
        },
        {
            "id": 3,
            "texto": "Texto dto 3",
            "data": [
                "lion3",
                "tiger3",
                "dog3"
            ]
        }
    ]
}

Flatten Output

{
  "myList.texto": [
    "Texto dto 1",
    "Texto dto 2",
    "Texto dto 3"
  ],
  "myList.data": [
    [
      "lion",
      "tiger",
      "dog"
    ],
    [
      "lion2",
      "tiger2",
      "dog2"
    ],
    [
      "lion3",
      "tiger3",
      "dog3"
    ]
  ],
  "myList.id": [
    1,
    2,
    3
  ]
}

The purpose of vizualice the data in the flatten output form is to know how to organice the data in the contract so can be available as a varible in the architect.
When I tried to fetch the data from myList.data using the GetAt method, the method fails because architect interpretates the output as a String Collection instead of a "Collection Collection".

Is there a way to actually access the data arrays values in architect? It would be great if you can help my with some contracts output configuration.

Regards,
Andrés V.

1 Like

@tim.smith @anon28066628 Do you have any idea how to handle this?

The way the flattening algorithm works, arrays of arrays generally can't be processed in whole in Architect. There may be ways you can approach compiling the contents of arrays into a single collection with the response config.

Thanks for your response @anon28066628, you have any configuration example to achieve this.

The only thing you can do in a case like this as far as I know is use jsonPath expressions in your translationMap like this:

"ids": "$.myList..id"

"textos": "$.myList..texto"

"data1": ".myList..data[0]" "data2": ".myList..data[1]"
"data3": "$.myList..data[2]"

But you have to make a hard-coded assumption about the number of entries in the data array. Do you need all the data at one time? You might use two actions - the first action that retrieves the list and looks through the ids only:

"ids": "$.myList..id"

And a second action that GETs specifically the object you want by id. Then the array will not be inside another array, and it will flatten.

Check out this website btw to paste in a sample response and test out different JSONPath expressions: http://jsonpath.com

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.