Skip to main content

Converting an object with key/values to a list

The following example automation shows you how to convert an object with key/values to a list (array):

an automation converting an object to a list.

an automation consisting of a Start block, a Variable block (someObj), and a Loop block containing two more Variable blocks (newObj and myList).

In the automation, we loop over the properties of the object. Inside the loop, we use a temporary variable of type object, called newObj. We set 2 keys in this object: property_name and property_value.

Property_name will be equal to the key of the item in the loop using { $.loop.index }:

Example of property names.

As above, but the newObj variable block is selected. The Key property_name is set to the Value of the loop index.

Property_value will be equal to the value of the item in the loop using { $.loop.item }:

An example of values.

As above. The Key property_value is set to the Value of the loop item.

Finally, we add the temporary object newObj to a variable of type list:

An object is added to a list.

As above, but the myList variable block is selected. New-Obj is added to myList.

The result is that we have converted someObj to myList.

Original someObj object:

{
  "key1": "val1",
  "key2": "val2"
}

Final myList array:

[
  {
    "property_name": "key1",
    "property_value": "val1"
  },
  {
    "property_name": "key2",
    "property_value": "val2"
  }
]

See also Loop block for more information on how to loop over properties of an object.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!