Tip – Deleting a Dictionary Quickly

Digging around a bit I saw that you can delete a dictionary by setting all it's keys to null. Most examples show using a For Each with the Dictionary Keys collection to set each key individually to null.

There is a way to do the same thing in a single step. Use the "Set Dictionary to JSON" action and pass it an empty JSON structure:

image

The "Set" means to replace all the existing keys with the keys from the JSON, but there are no keys in the JSON (while still being valid JSON) so it effectively removes all keys, which causes KM to delete the whole dictionary.

Here's an example macro that will let you pick from a list of your current dictionaries and delete the selected one.

Remove Selected Dictionary.kmmacros (3.0 KB)

3 Likes

I've written a macro that lets me view, delete, display, modify keys for, and gets statistics on, all the dictionaries that I have. I think it's about time I post it, because I've been using it for months and it's delightful. My only regret is that my skill with Custom HTML Forms is weak so it doesn't look as appealing as it could. Maybe someone else can touch it up a bit.

2 Likes