Number of Dictionary Entries

Is there a function that returns the number of items in a dictionary?

Thank you.

I can't find an obvious way, but this will work:

2022-01-23_05-34-39

 
In this example, the result is in Local_NumberOfKeys

Here's the text from the first action:

%JSONFromDictionaryPretty%TestDictionary% 

Note the use of the "Pretty" version of the token. It's required, or you won't get the correct count.

Click for Explanation

Consider this dictionary:

image

 
If you convert it to JSON using the %JSONFromDictionaryPretty% token, you get this:

{
  "Key1": "Value1",
  "Key2": "Value2",
  "Key3": "Value3",
  "key4": "vau4",
  "key5": "value5\nvalue 5 second line"
}

So you can use the Filter Variable action ("Filter Text", actually) to count the number of lines in the JSON string:

2022-01-23_05-34-18

 
Using the above example, that gives us a count of 7, which includes the opening and closing curly braces.

So just subtract 2 from the count, and you're good to go.

2 Likes

Thanks so much!

1 Like