Understanding "Get Dictionary Value"

Hi guys,

I’m struggling a bit with understanding a certain part of the “Get Dictionary Value” action.

What I Know:

If I have a dictionary that looks like this:
{"data":{"first":"one","second":"two","third":[{"three":"lolcat"}],"fourth":"four"}}, to get the value for second I would

  1. Get Dictionary Value: data
  2. Get Dictionary Value: second
  3. Output will be: two

But how do I get the value for three (which would be lolcat)?

Technically it’s place as third.0 but Shortcuts doesn’t recognize that, instead asking me to select from a menu which key I’d move on with (and they a all just named Dictionary.

I know It’s always 0 (in my specific case) but trying

  1. Get Dictionary Value: 0

doesn’t work. It just returns empty.

Help? :slight_smile:

m.

Aren’t dictionaries 1-based in Shortcuts, rather than starting at index 0?

Alternatively, getting dictionary value “third” returns a dictionary, so can you try to get dictionary value “three” of dictionary value “third”.

Doesn’t Compute. No matter what setup I try, I still get that annoying menu.

If I select the top option it returns data as expected. I just can’t get it to select it automatically.

I’ve tried Get Dictionary Value: 0, data.0 and data[0].

It always helps to post your Shortcut, but I think I get it now. If a menu is coming up, it’s asking you to input an index or key.
Try entering “three” or “1”. (Not “0”, like I said, the dictionary starts at 1, plus there’s no key called “0”.

Or see these two methods:

Oh, and if the “1” at the end is in grey, that means you have specified an index yet.

In addition to the above, and assuming you haven’t already, take a look at the this page in the Apple support guide and the list handling page it links to at the end.

@GraemeS - thank you! The Index solution worked :slight_smile:

Thank you @sylumer! While it isn’t an exact match to my problem, it definitely made me wiser on dictionaries :slight_smile: