Objects contain key-value pairs called "properties". A property key (name) is always a string, but the value can be of any data type. You can use objects to store information.

You can create, access and edit objects using Expression language (AEL) and JavaScript. Below, you will find all of the AEL methods that can be used on objects.

Properties inside an object are not ordered, so you can't access them by their index (position), only by their keys (names).

πŸ“˜

Arrays of objects

Arrays of objects are a very common way to store large datasets. You can access and process them by using Array methods. Learn more about arrays of objects here.

Syntax

  • Objects are contained within curly brackets {}.
  • Each property is a key-value pair separated by a colon :, like this: "someKey": true.
  • Property keys (names) should be a string without any whitespaces or special characters. They can be contained within double quotation marks "".
  • Property values can be of any data type, eg. a string, boolean, array or even another object.
  • Both property keys and values can store dynamic values (eg. system.currentTime, nlu.intent or variables stored in Memory).
  • Object properties are separated by commas ,. Remember not to add a comma after the last property!
  • Spaces and line breaks are not important. An object definition can span multiple lines - and they usually are for better readability.
  • Object properties are unordered. It doesn't matter in which order the properties were set up.

🚧

Custom object methods are not allowed in Automate

Normally, JavaScript allows to store functions as object values. Such functions are called "methods".
But in Automate, methods are not allowed in both Expression language and JavaScript.

Examples

In Automate, objects are frequently found in responses from external APIs, Knowledge Base and Memory.

596

An object with dynamic value system.currentTime saved to Memory and printed in Response.

793

An array of objects stored as a Knowledge Base record.

Full list of object methods and operations

Method/operationDescription
Create an objectInitialize an object using literal constructor, eg. {"someKey": "someValue"}.
Access a propertyAccess property value by its name using bracket or dot notation.
Add or change a propertyAdd a new property to an existing object or assign a new value to an existing property.
property()Access property value (including dynamic values).
getKeys()Get an array with all object property names.

Create an object

To create an object (e.g. when setting variable in memory), simply input wished object using curly brackets, colons and comas. In JS, it is called 'literal constructor'.

Examples:

{
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true
 }
// This object will store dynamic values from NLU API as its property values. 

{
"intents": nlu.intentsList,
"variables": nlu.variablesList
}

Access a property

Access specific property value by its name using bracket or dot notation.

Dot notation
memory.someObject.propertyName

Bracket notation
memory.someObject["propertyName"]

To access a property using a dynamic value, use bracket notation without quotation marks:
memory.someObject[memory.savedPropertyName]

Properties inside an object are not ordered, so you can't access them by their index (position), only by their keys (names).

// For an object:
memory.employee = {
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true
 }

// Access firstName:
memory.employee.firstName
// Result:
"Jim"

// Create a string with the full name:
memory.employee.firstName + " " + memory.employee.lastName
// Result:
"Jim Halpert"
// For an object:
memory.employee = {
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true
 }
// and for an intent recognized by NLU:
nlu.intent = "age"

// Access a property defined by recognized intent:
memory.employee[nlu.intent]
// Result:
32

Create or change a property

Create a property or update a value of an existing property of an object stored in Memory using dot notation. As a key, input an object name followed by a dot and a property's name to be created or updated.

Example

After being created in the 1st input, the objectmemory.employee1 contains 4 properties. The 2nd input adds a 5th property yearlyBonus and sets its value to $240. The 3rd input updates age by adding 1 to its previous value.

Results of printing {memory.employee1} in a response after each input:

{
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true
 }
{
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true,
   yearlyBonus: "$240"
 }
{
   firstName: "Jim",
   lastName: "Halpert",
   age: 33,
   activeEmployee: true,
   yearlyBonus: "$240"
 }

property()

If property name is dynamic (e.g. other memory field and/or it's not valid name) then we can use method property()

Access specific property value by its name given as an argument (inside the brackets). This method accepts dynamic values (eg. other memory values or NLU results).

// For an object:
memory.employee = {
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true
 }
// and for an intent recognized by NLU:
nlu.intent = "age"

// Access a property defined by recognized intent:
memory.employee.property(nlu.intent)
// Result:
32

getKeys()

Create an array containing all of the object's property keys.

As object's properties are always unordered, elements in the created array may have different order than that in which the user defined them in an object or how they look like when the object is printed in a response.

// For an object:
memory.employee = {
   firstName: "Jim",
   lastName: "Halpert",
   age: 32,
   activeEmployee: true
 }

// Create an array using getKeys():
memory.employee.getKeys();

// Result:
[
"activeEmployee",
"firstName",
"age",
"lastName"
]