kmCount
Returns how many items are in a list or JSON array, or keys in a record.
Keyboard Maestro: COUNT
Details #
kmCount() or kmCount(value) takes zero or one argument and returns a number.
With a value: a list or record gives its item or key count, and text is parsed as JSON first. Anything else (a number, text that isn't a JSON array or object) gives 0.
With no argument it counts the variable kmJSONArray, or failing that json, and gives 0 if neither is set.
Parameters #
Takes 0 to 1 argument.
{{ kmCount(text?) }}
Examples #
kmCount(items)→
3| Sample variable | Value |
|---|---|
items | ["a", "b", "c"] |
kmCount(text)→
4| Sample variable | Value |
|---|---|
text | [1, 2, 3, 4] |
Gotchas #
Text that isn't JSON counts as 0, not an error. For plain counting use length.
Keyboard Maestro's COUNT only works while evaluating a JSON path; here it is an ordinary function.