OBJECT.MERGE
merges two or more objects. If the same key is present multiple times, the rightmost value will be used. This function can accept an arbitrary number of objects or key/value pairs.
Function category: Object​
OBJECT.MERGE(arg1, [arg2...])
Arguments | Description |
| Object or key/value pair. |
| Optional. Has the same restrictions as |
Any argument can also contain a dynamic reference to the current data context, which is accessed with the _ character.
Let's say we're given a response with the following vehicle performance information.
{"data": {"vin": "3VWJP7AT9CM624721","vehicle": {"fuel_efficiency": 95,"breaking_time": 2400},"fleets": ["alpha", "bravo", "charlie"],},"active_fleet": {"active": true,"name": ""}}
If we want to merge the vehicles VIN into the vehicle
hash, use the following function.
# Merge objects into a hashOBJECT.MERGE(data.vehicle, {{"VIN", data.vin}})​# the first argument data.vehicle# is a hash referenced in the context
This returns the following.
{ "VIN": "3VWJP7AT9CM624721", "fuel_efficiency": 95, "breaking_time": 2400 }
It is also possible to employ the dynamic reference character in using OBJECT.MERGE
. For instance, if we wanted to generate a set of objects describing fleet activity status, use the following function.
# Generate objects using dynamic reference characterMAP(OBJECT.MERGE(FN(x, {{data.active_fleet, x}}), MAP(FN(x, OBJECT.NEW({{"name", x}})), data.fleets))
This returns the following.
[{ "active": true, "name": "alpha" },{ "active": true, "name": "bravo" },{ "active": true, "name": "charlie" }]