How to use JSON Arrays?

How to use JSON Arrays?

  

OutSystems 10

We're trying to use JSON Arrays in a REST webservice, deserialize them and read them, but I can't get OutSystems to stop throwing errors when it sees an array in the call.  For example,

{
"ListOfChildren":
[ "Pete",
  "Chris"]
}


Valid JSON, but I can't deserialize into text, text record list, or text list.  Structure is:

JSONRequest

-- ListOfChildren  (Text Record List)


Any insight as to where I'm going wrong?

EDIT:  Are there any examples of using JSON arrays in OutSystems anywhere?

Solution

Hello Chris,

I've attached an example that exposes and consumes a REST service with a list/array.
It works without problem.

If OutSystems is complaining about the array, my bet is that your structure is not defined as it should be. How are you consuming the Service? Are you building the structure yourself or are you consuming the service (in this case, it should work out of the box).

https://eduardojauch.outsystemscloud.com/RestExample/Home.aspx?_ts=636477532374048961

Cheers,
Eduardo Jauch

Solution

Ah, thanks - got it now.  We had a few problems.  The JSON example we were given by another dev wasn't correctly formatted, so the arrays were wrong anyway.  And I was making the call with the name of the 'outer' call in the request, so the deserialization was failing because it saw an extra layer in the JSON structure.

Thanks for your assistance.

Eduardo Jauch wrote:

Hello Chris,

I've attached an example that exposes and consumes a REST service with a list/array.
It works without problem.

If OutSystems is complaining about the array, my bet is that your structure is not defined as it should be. How are you consuming the Service? Are you building the structure yourself or are you consuming the service (in this case, it should work out of the box).

https://eduardojauch.outsystemscloud.com/RestExample/Home.aspx?_ts=636477532374048961

Cheers,
Eduardo Jauch

hi, do you have this module in version 9.1? I am unable to open it as the version you have is greater than the one I have.


Hi Karin

No. Don't have access to a version 9.1 environment.

But you can open it in a personal environment (version 10).

Cheers