Skip to content

OBJECT.NEW

Daniel Gorman edited this page May 3, 2019 · 2 revisions

The OBJECT.NEW Function

Function Group: Object

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.

Syntax

OBJECT.NEW(arg1)

  • arg1 is a collection of key/value pairs.
  • arg1 can also contain a dynamic reference to the current data context, which is accessed with the _ character.

Uses

Let's say we're given a response with some vehicle performance information that looks like this:

{
  "data": {
    "vin": "3VWJP7AT9CM624721",
    "vehicle": {
      "fuel_efficiency": 95,
      "breaking_time": 2400
    },
    "fleets": ["alpha", "bravo", "charlie"]
  }
}

If we want to create a new object, we can used the OBJECT.NEW function like this:

OBJECT.NEW({{data.vin, data.vehicle}})

This would return:

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

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, we could do so like this:

MAP(OBJECT.NEW({{"fleet_name", _}}), data.fleets)

This would return:

[ 
  { "fleet_name": "alpha" }, 
  { "fleet_name": "bravo" },
  { "fleet_name": "charlie" }
]
Clone this wiki locally