Dictionary size error

I'm trying to count the number of KVP in a dictionary using the block 'size of dictionary',


but get an error message. I believe that the dict is OK since it works correctly when I'm looking up a value for any of the keys. What's wrong?

I get the same error when I try this:

A closer look at my debug dump reveals that the dictionary is not a dict, but a list of JSON objects.


I now use the block 'length of list' and that solves the problem. I was misled by the fact that the variable was initialized as an empty dictionary, populated with the list of JSON KVP without any complaints and accessing that list as a dictionary works without errors.

image

So you did something to global SF_GenErrors that changed its data type, but did not show us the code that did that.

Not knowingly.
Init:
image

Fist assignment of data:
image
image

Raw JSON from where the data are extracted:
image
... etc.

Mhhhh... I smell a rat.
I've extracted a dictionary from the JSON string using the web component, but continued to use the raw JSON string further in the code and used it as if it were the extracted dictionary. Currently reviewing the code, replacing the references to the JSON string by references to the extracted dicts. Will take a while to sort this mess. Unfortunately AI2 didn't complain about using the raw JSON iso dictionaries, hence I never noticed this - until now.

1 Like

Yep - it's right there under your nose. The most difficult code to debug is your own code, you see incorrect code as correct code. It is the same with a paragraph of text that has spelling and grammar errors, even words written backwards - the human brain just reads it all correctly :grin: