OBJECT.NEW

OBJECT.NEW generates a new Object from a collection of key/value pairs. If the same key is present multiple times, the rightmost value will be used.

Function category: Object‚Äč

Syntax

OBJECT.NEW(arg1)

Arguments

Description

arg1

Collection of key/value pairs

arg1 can also contain a dynamic reference to the current data context, which is accessed with the _ character.

Examples

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"]
}
}

Example 1: Create a new object

If we want to create a new object, use the following function.

# Create a new objectd
OBJECT.NEW({{data.vin, data.vehicle}})

This return the following:

{ "3VWJP7AT9CM624721": { "fuel_efficiency": 95, "breaking_time": 2400 } }

Example 2: Using the dynamic reference character ( _ )

It is also possible to employ the dynamic reference character (_) in using OBJECT.NEW. For instance, if we wanted to parse the fleet names into an array of objects, use the following function.

# Parse into an array using the dynamic reference
MAP(OBJECT.NEW({{"fleet_name", _}}), data.fleets)

This returns the following:

[
{ "fleet_name": "alpha" },
{ "fleet_name": "bravo" },
{ "fleet_name": "charlie" }
]