Set Dictionary Value Using Dot Notation

I find dot notation a very convenient way of accessing individual information items in nested dictionary structures. For example in a nested set of dictionaries comprising countries, states and their details you could access a key such as USA.California.Population.

Data Jar supports dot notation for both getting and setting values, but unfortunately Shortcuts only currently supports this for getting values.

To work around this, I put together a shortcut that allows the setting of a dictionary value using dot notation, which I’ve linked to below. I’ve also included another Shortcut I used to test this, which illustrates how it is used.

Set Value Using Dot Notation
Dot Notation Test

The shortcut is called with a dictionary comprising

  • Dictionary to be updated
  • Key to be set
  • Value to set it to

The shortcut uses recursion (I.e. calls itself repeatedly) in order to walk down the dictionary tree.

I’m guessing there are probably other solutions out there for doing this, but it’s one of those things I wanted to attempt myself initially as a learning exercise (although I think the main thing I learned is that while recursion is an easy concept for computers, it’s much harder for my brain !).

Interested in other techniques people have adopted to address this shortcoming ?

Just a health warning on the shortcut above, while I have tested it in a number of scenarios, there may be some edge cases it does not handle. Also it does not include the same levels of protection for overwriting arrays and dictionaries as Data Jar so use with care.