Skip to main content

Records

Construction

A record is an object that has zero or more name-value pairs. A record can be denoted by record literal. For example, {name: "Bob", age: 10 + 20} is a record with two fields, name and age. The name field is a string with value "Bob", while the age field is a number with value 30.

Records can be arbitrarily nested and have values of any type. For example, these are all legal records:

  • {a: 1, b: {c: 2, d: 3}} is a record with two fields, a and b, where the value of b is a record with two further fields, c and d.
  • {name: "Bob", age: 30, friends: ["John", "Jane"]} is a record where the friends field is a list of strings.

Additionally, a field name can be defined using double quotes and can be any inline string. Here are two examples.

  • { "Device Count": 35971 } is a record where the only field name includes spaces. A space is a special character.
  • { "Management IP(s)": [ipAddress("1.1.1.1"), ipAddress("2.2.2.2")] } is a record where the only field name includes the special characters ( and ).

Selection

. Operator

The primary operation to consume a record is the dot-operator ., which selects a field value from a record. For example:

  • {name: "Bob", age: 10 + 20}.name has value "Bob".
  • r.age is 30 if r is bound to {name: "Bob", age: 10 + 20}.
  • r.age terminates the execution of the query with an error if r is bound to null.

?. Operator

Another operation to consume a record is the null-conditional dot-operator, which behaves the same as the dot-operator, except that it propagates null when applied to a null record instead of raising an error. In other words, the ?. operator selects a field value from a record if the record is not null but returns null if the record is null. For example:

  • {name: "Bob", age: 10 + 20}?.name has value "Bob".
  • r?.age is null if r is bound to null.

If r is bound to null, then the execution of r?.b.c will terminate with an error because r?.b returns null and then the attempt to access field c on that null value will fail.

[] and ?[] Operators

A record field containing a special character cannot be selected using either of the previous two operators: . and ?.. Instead, such a field is selected using the square-brackets operator [], which looks like r["Device Count"] for some record r. Just like with the . operator, the [] operator can be preceeded by a ? to form the null-conditional square-brackets operator ?[], which looks like r?["Device Count"] for some record r.

Here are self-contained examples using the [] and ?[] operators.

  • r = { "Device Count": 35971 }; deviceCount = r["Device Count"]; assigns the values 35971 to deviceCount.
  • r = null : { "Device Count": Number }; deviceCount = r?["Device Count"]; assigns the null to deviceCount.