I'm working with a complex JSON response from a business partner and there is a nested object that references deviceSettings:segment as an object and then as an array in a different place. The problem is the OutSystems structure crawls exactly the same tags down to both the object and the array.

See the examples below.

I think this would be less of an issue if the parent arrays and parent objects were tagged uniquely. Maybe I am doing something wrong?

Here it is as an object (modules{}>refs{}>deviceSettings:segment{})

Here it is as an array (modules{}>refs{}>deviceSettings:segment[])


I've set this to either an object (REGULAR) or an array (REGULAR List), and when it tries to parse it, it produces an error about expecting either an object or an array.

I think this would be less of an issue if the parent arrays and parent objects were tagged uniquely. Maybe I am doing something wrong?


Unfortunately, this is one of the REST integration cases that aren't handled OOTB and require some tinkering.


Your best bet is to use the OnAfterResponse mechanism and manipulate the ResponseText before it is converted to Structure form. You should ensure that the value of the "deviceSettings:segment" field is always of type "List", so that it can be safely converted to a "REGULAR2 List".


This means adding the square brackets whenever the service responds with a single Object rather than a List of Objects.

Gonçalo - I understand what you are suggesting, but I'm not sure how I would even begin to attempt that.  While finding a string with a value of  "deviceSettings\:segment": {" and inserting an opening square bracket isn't terribly difficult, finding the end of the object to insert the closing square bracket isn't.

Ideally, you would integrate a JSON parser such as Jackson in Integration Studio and handle this case in native Java or C# code.


Alternatively, two less reliable options include:

  1. Using ArdoJSON's JSONSelect action to identify the length of the "dynamicSettings:segment" field, and manipulating the text using this action

  2. Using the Text and HTML Processing's RegexReplace action to manipulate the JSON via Regular Expression (see picture below).

    I've setup a Regex 101 example that supports single-nesting of objects and arrays.
    The Regex assumes a minmised JSON response, and it is not 100% safe against malformed JSON responses, however in this particular case the platform will perform JSON validation for you anyway.