The Object Data Type is used to group together a set of named values called keys. Each value will be associated with a key, later that value can be retrieved by the same key. An Object is created by a comma separated list of pairs where a name is separated from the value by a colon, enclosed in curly brackets. For example, if we wanted to pair foo with 1, bar with 2, and baz with 3 we would write the following Airscript.
{
foo: 1,
bar: 2,
baz: 3
}
Alternatively, instead of just using the keyword foo, a string may be provided. The following Airscript Expression will produced the same value as that from the previous example.
{
"foo": 1,
"bar": 2,
"baz": 3
}
This syntax is useful if a key must contain a character that isn't normally allowed in identifiers. For example, the key foo-bar must be entered with a string because the - character is not allowed.
{
"foo-bar": 1
}
Using strings as keys also allows you to create Objects that have dynamic keys. For example, if there is a String Variable named dynamic_object_key
that holds the string "foo", one can use, in order to retrieve the value associated with foo, an appended "." and then the text foo.
my_record.foo
Alternatively, records can also be accessed similarly to lists. So we may also access the value associated with foo like this:
my_record["foo"]