A dictionary is similar to a thing, but with key differences. Unlike a thing, a dictionary has no ID and accepts keys of type int, uuid or str without restrictions (e.g. property "#" is reserved and cannot be used on a thing, but is valid as a dict key).
When returned in a client response, a dict is formatted as an array of key-value pairs (nested arrays). This preserves JSON compatibility, where integer keys are unsupported, and prevents potential duplicate keys caused by converting UUIDs to strings. Note that the order of the resulting array is not guaranteed and should be treated like an unordered map or object.
| Function | Description |
|---|---|
| clear | Remove all items from the dict. |
| copy | Copy a dict. |
| del | Delete an item from the dict by its key. |
| dup | Duplicate a dict. |
| each | Iterate over all items in a dict. |
| get | Return the value of an item by its key. If the key is not found, return nil unless an alternative default value is given. |
| has | Determine if the dict has a given key. |
| keys | Return a list with all the keys of the dict. |
| len | Return the number of items in the dict. |
| map | Iterate over all items in a dict and return a list with the results of each iteration. |
| restriction | Return the key/value restriction of the dict, or ["any", "any"] if no restriction is set. |
| set | Set an item in a dict. If the key already exists, the old value will be overwritten. |
| values | Return a list with all the values of the dict. |
| Function | Description |
|---|---|
| is_dict | Test if a given value is of type dict. |