Dictionary Helper for Shortcut Developers

Add, change, remove items using dot notation


Description

Run Dictionary Helper from your shortcut to modify dictionaries with ease. It allows you to add/change/remove dictionary values using dot notation (more on dot notation: https://www.reddit.com/r/shortcuts/comments/cyqpj3/working_with_dictionaries_part_3_accessing_values/). The Shortcuts app lets you access dictionary values using dot notation, but does not support dot notation for setting or removing values. This helper was made as simple to use as possible.

  • Adding or Changing Values
    • To set a value, you need to pass the dictionary, key and value to the helper. Do this by wrapping them in another dictionary with keys "dictionary", "key" and "value".
    • There are several ways to compose a dictionary. For example:
      • Create a Dictionary action with "key" using dot notation, and set values for "dictionary" and "value" using Set Dictionary Value actions. The value can be of any type.
      • Create a Text action containing a text form of dictionary (JSON) with "dictionary", "key" and "value". You can use this method if the value is of type number, boolean or dictionary, but NOT list or text.
  • Removing Values
    • You need to pass the dictionary and key to the helper, wrapped in another dictionary in the same way.

Pass the dictionary to the helper, and it will return a modified dictionary!

  • If the target is a list, i.e. the last element in dot notation is a number, then sending a new value will insert the value to the position, not removing the existing item. If you want to modify a list item, then remove the item and set a new value.
  • If the list index number is bigger than the size of the list, the value will be appended at the end of the list.
  • If your key contains a dot character(.) then enclose the key in double quotes (e.g., chapter."1.2".author).
  • Key elements only with numeric characters will always be treated as list indices.
  • The helper will return nothing if there was an error. (Or would you like to get the original dictionary?)

Also check out Dictionary Action Builder, another neat utility for shortcut developers.

UpdateHub


Latest Release Notes

1.02 - May 2, 2020, 1:06 p.m.

• Bug fixes
• Added support for UpdateHub


Past versions