List and Dictionary Helper
Add, replace, remove list or dictionary values
What this shortcut does
๐ Get Shortcut without Login Run List and Dictionary Helper from your shortcut to modify a list or dictionary. It allows you to add, replace or remove an item using dot notation. Working with a list To delete an item from a list, pass a dictionary containing index and list to the shortcut. For example, to remove the second item from myList, pass {"index":2, "list":myList} . Use two Set Dictionary Value actions to create the dictionary; set index first, followed by list as shown in the image below. The shortcut returns a modified list. To insert an item, pass a dictionary of index , value and list . Set index first then value and list . You can use a negative index to refer to an item from the end of the list. -1 is the last item, -2 is the second to last, etc. For example, to insert text "Zillion" between "Two" and "Three", you can pass {"index":-2, "value":"Zillion", "list":myList} as shown in the image. Zero index will append the value at the end. To replace an item, first remove it and then insert the new value to the same index. Working with a dictionary To delete an item from a dictionary, pass a dictionary of key and dictionary . For example, to remove the type value from the second phones data, pass {"key":"phones.2.type", "dictionary":myDict} as shown in the image. Make sure that the type of myDict is Dictionary. To add or replace an item, pass a dictionary of key , value and dictionary . For both lists and dictionaries, the value can be of any type; text, number, boolean, dictionary or list. Notes If a key contains a dot in its name, enclose it in double quotes (e.g., chapter."1.2".author ). index and key are interchangeable. That is, you can use key on a list and vice versa. Likewise, list and dictionary keys are interchangeable. If you try to insert a value to a non-list item, the item will become a list and the new value will be inserted. For example, passing key or index animals.1 and value "cat" to {"animals":"dog"} will return {"animals":["cat","dog"]} . This is similar to how Add to Variable works. You can use dot notation on a list to modify a dictionary inside. For example, passing 2.cat as index or key to ["hi",{"cat":"Tom","mouse":"Jerry"}, 42] will return ["hi",{"mouse":"Jerry"}, 42] . Also check out Dictionary Action Builder , another neat utility for shortcut developers.