Marshalling (writing) and unmarshalling (reading) is used both on the client / sender (upstream) and server / receiver (downstream) side of the GLU engine.
The incoming request into the GLU engine is UNMARSHALLED (read) into the GLU Object Model (JSON). This could be an inbound request or an outbound response. The unmarshalling can either be saving a like for like array, looking for certain values, or saving only part of the contents of the array.
Note: See the response template details for how to include the array in the response. Response Manager
Unmarshalling like for like arrays
If my response from a third party looked like this:
{"result": [ { "accountID": 0, "amount": 17209, "balanceType": "Savings" }, { "accountID": 1, "amount": 0, "balanceType": "Money" }, { "accountID": 23, "amount": 0, "balanceType": "Money" }, { "accountID": 65, "amount": 0, "balanceType": "Money" }, { "accountID": 1018, "amount": 0, "balanceType": "Money" }, { "accountID": 1018, "amount": 0, "balanceType": "Money" } ]}
For each parameter in the array, the unmarshalling and parameter properties would be defined as below. In the unmarshalling, the object/collection path defines the path where to find the array as well as the attribute inside it to take to save into the parameter. In the properties, the parameter name is specified as well as the object (array name) in which the parameter will be saved.
save into the parameter. In the properties, the parameter name is specified as well as the object (array name) in which the parameter will be saved.

Unmarshalling from unnamed arrays
If my response from a third party looked like this:
[ { "veggieName": "potato", "veggieLike": true }, { "veggieName": "broccoli", "veggieLike": false } ]
You can follow the above steps and replace the name of the array with empty square brackets – as shown in the ‘Object / Collection Path’ field below.

Marshalling to unnamed arrays
Should I want to marshall an array and save it as an unnamed array, I can use the ‘Store as Object’ option. Hence, the array will be stored as an object (unnamed array)e.g From:
{ "array": [ { "attribute": "value1" }, { "attribute": "value1" } ] }
To:
[ { "attribute": "value1" }, { "attribute": "value1" } ]


Unmarshalling/Marshalling array of values
If the response form third party looks like this:
{
arrayOfValues”:[16,6,2,8]
}

You can follow the above steps, but leave the attributes fields empty to unmarshall or to marshall.
Unmarshalling using a condition
If my response from a third party looked like this:
{"result": [ { "accountID": 0, "amount": 17209, "balanceType": "Savings" }, { "accountID": 1, "amount": 0, "balanceType": "Money" }, { "accountID": 23, "amount": 0, "balanceType": "Money" }, { "accountID": 65, "amount": 0, "balanceType": "Money" }, { "accountID": 1018, "amount": 0, "balanceType": "Money" }, { "accountID": 1018, "amount": 0, "balanceType": "Money" } ]}
Should I want to only find the balance on accountID = 0, I can add to my unmarshalling configuration a condition. This condition needs to be met within one of the records within the array. Because I only expect the result set to have one instance of this condition being met, I can save this to a single parameter. Should there be multiple, I can save it to the parameter but then also need to include the object (array) name in the property object field.

Unmarshalling only part of the array contents
Using the example above, should I only want to unmarshal the array and save the accountID and amount field into an array, then only those 2 parameters need to be added in the response parameters with the correct configuration included for unmarshalling. This will create the new accounts object without the balanceType parameter.
Consolidating amounts in an array
If I received an array with multiple records for one unique identifier (e.g. accountID) and you wanted to return a consolidated / overall balance for each accountID you could use the following function. This function could be executed on a response handler once the array has been unmarshalled into the engine. It is available in GLU Functions & Formulas
CONSOLIDATE(${accounts},accountID,amount)
- parameter 1 (arrayName): the array name where you have unmarshalled your data to
- -parameter 2 (paramNameConsolidateBy): consolidate to this identifier
- -parameter 3 (paramNameToConsolidate): the parameter which you want to add up The above example would work for an incoming array looking like this:
{"result": [ { "accountID": 65, "amount": 0 }, { "accountID": 1018, "amount": 10 }, { "accountID": 1018, "amount": 20 } ]}
The output would look like this:
{"accounts": [ { "accountID": 65, "amount": 0 }, { "accountID": 1018, "amount": 30 } ]}
In your configuration, you would first set a derived parameter. As part of your response parameters, you would unmarshall the parameters that you require into an accounts array. Then on your response handler, you can use a ‘none’ handler to overwrite your derived parameter with your function. See example below.

Unmarshalling a specific position in an array
You can access a specific position in an array by using a shortcut.
{"accounts": [ { "accountID": 65, "amount": 0 }, { "accountID": 1018, "amount": 30 } ]}
In the accounts array – to get the first account ID value out the array – you can use: ${accounts[0].accountID} accounts – arrayName [0] – position in the array accountID – the value in the first record you want to retrieve