Failure to find dictionary content

Hello,

When I try to make a local variable to pull my mission data using the list index, it fails to find it. I can't figure out why. Can anyone help me figure out what I'm doing wrong? I also provided the result of the "call_log" function at the end of the block.

Screenshot 2026-02-23 07.40.36

Probably I should let others with proper knowledge answer and I am not sure if this is helpful or not (and I do not quite understand what I am writing), but I also had similar problem. I do not quite remember what really happened, but it had something to do with how data is stored in dictionaries. I had to introduce some json decoding when I was reading back a list from a dictionary. I attach a screenshot of part of my code.

What is that 1 at the top ? Is this a part of your data ?

Next check if you actually have a dictionary and not a json string.

What are your variables SelectionIndex and startValue do they correspond with your data ?

The one at the top is the selection index.

How do I check to see if I have a dictionary or json string? I created a dictionary with keys (what are being called to the text boxes and labels) and then passed the house to this page as the start value text. The calllog function is showing you the value of the selection index, and the value of thelist item holding the dictionary that I am trying to get keys out of on the page.

The first key in the dictionary is 1. The selection index is 1. But it can't find it.

When extracting deeply nested data from a dictionary of dictionaries, you work your way from the outside in.

Blocks are evaluated right to left, so the outer key should be used on the rightmost blocks, and the inner keys on the left of that.

Use the Companion Do It facility to see what is in everything, working your way right to left.

Something like this:

Would it be better to rewrite the function that imports the house data from the CSV file (which the mission list gets added to later) as solely using dictionaries instead of a dictionary of lists where the 4th item in the list has another dictionary? Would that make the data easier for the mit app inventor to parse correctly when it reads or stores it?

Right now, my current data is created on the previous screen and stored in a tinydb like this:
TinyDB key: Houses
value: Dictionary {
Key: House
Value: List [
1: Integer
2: List [2-4 integers]
3: String
4: Dictionary {
Key: 1 Value: Dictionary {
Key: difficulty Value: Integer
Key: mission type Value: Integer
Key: do for Value: string
Key: do to Value: string
}
}
]
}

Thank you for this insight! If you look at the call log block, you'll see that it mirrors current_mission_data all the way up to the final get value for key block. I was attempting to illustrate that I had been able to successfully follow it all the way to there, but I can't seem to find the dictionary at that value (that is shown to exist in the log) to pull data from it.

Do It is your friend.

This does not answer your original question, but I took this as a learning opportunity to create a TinyDB database (with key "Houses" and a list of length 1 of a "House" dictionary, according to your description).

I could recall (by pressing Button 2) the "difficulty value" entry from the innermost dictionary when I used Json conversion when reading the TinyDB data, but I got an error message when I tried to access this data without Json conversion using Button 1.

Here is the aia file I used:
dictionaryTrial.aia (3.4 KB)

It should therefore look like this?

{"Houses":{"House": [5,[1,2,3,4],"String",{"1":{"difficulty":4,"mission type": 2,"do for":"stringdofor","do to":"stringdoto"}}]}}

Houses also need to be inside curly brackets.

Unless you have saved this to tinydb directly as a dictionary, this will be treated as a json string when you call it back. With your data in this format, you should be able to traverse the dictionary at any level and return the data you require.

To be honest, I'm still not sure what was wrong. Do it (I didn't know what this was and had to look it up!) was definitely a good plan, and I ended up reworking my code so that I only had lists stored inside of lists. My code now works! I'm assuming there's a weird bug or something in how the data is parsed that is causing it to lose track of what it's trying to read when you nest dictionaries in lists in dictionaries etc.

Probably a best practice to avoid doing this whenever possible. Keep to storing dictionaries in dictionaries, and storing lists in dictionaries whenever possible.

What you say is not strictly correct.

You can have a dictionary inside a list, and you can have a list inside a dictionary. You just have to get the syntax correct, and know when to use a list block and when to use a dictionary block when traversing the "json"

Yeah, I think this is what I posted above with my data structure? Unfortunately, this entire structure is created (then added to) as a dictionary in a tinydb directly. Here is the block where I create the initial database!

Also, I ended up rewriting how I store the final dictionaries as lists, and the code works now, so at this point everything we talk about is theoretical. I did want to take a minute to reply to you :slight_smile:

Also I want to recognize that you've responded directly to both issues I've had to ask for help about, and I really appreciate you and @ABG for that! I am incredibly grateful.

If we have a look at your data structure:

Note I call the local variable houseDict, not houseList, because you are creating a dictionary!

I want to return the second item in the list in the value for Dog, I get Border Collie, which is correct.

Right, and in the original block that I shared, you can see that I was able to successfully navigate to the dictionary in question. However, when I attempted to pull a key value from that dictionary that matched, it returned nothing. If I attempted to pull it as a list, it said that I had a poorly formed list of pairs (I think?). When I attempted to decode it as json, I also received an error message.

Here is the code I use to generate missions. As you can see, it now creates the missions as a list of lists instead of a dictionary of dictionaires, and the information inside that list is now also a list instead of a dictionary.

I can now successfully pull the data for each mission, although I had to do some fancy footwork to translate the selection index to always match the mission index inside each house.

Like I said, I don't know what was going wrong. The data was being successfully created and stored inside the list as a dictionary of dictionaries of missions with keys equal to each value that I wanted to generate for that mission type. However, I couldn't retrieve it. As far as I can tell, I was doing everything correctly at the time. Once I shifted to creating and storing the information in lists, it works fine.

Going back to your original stored data structure:

{"Houses":{"House": [5,[1,2,3,4],"String",{"1":{"difficulty":4,"mission type": 2,"do for":"stringdofor","do to":"stringdoto"}}]}}

You have a dict ({difficulty...) inside a dict (1), inside a list ([5..], inside a dict (House), inside a dict (Houses).

These blocks work:

One important setting to note, use a text block to get the value where 1 is a key inside double quotes (all keys are inside double quotes)

You could "simplify" by using the walking at key path block like so (for "difficulty" only here)

I need to use the selection index to determine the value of the key, so I can't just use "1" or "2" etc. Is there a way to translate that to a string?

It seems that's where this was failing. Would using the join block with just one input work?

Yes use a join block to do this:

image

See above as I have added the walking by key path method as well