dict error "cannot read dictionary: 0"

Adam's icon

Can someone help me with this? I'm trying to load a json file into [dict] but I keep getting this error "dict cannot read dictionary: 0". I put the file right in the search Max6 search path but that doesn't help. Is there a particular way that the json data needs to be formatted for dict to work with it? I've never used dict before in a patch but I'm trying to sonify a lot of data and I think this would be the best way to go about it. Thanks in advance for the help.

Andro's icon

Try putting it into dict.pack then to dict

Adam's icon

Thanks for getting back to Andro. I was able to get dict to start working if I removed everything from the json file except for one set of entries. Like this....

{
"field1" : "info"
|
|
|
"field_n" : "info_n"
}

The issue I'm running into now is that the original data has about 60 of these blocks of entries. The project I've been asked to work on uses statistics from the FBI's public database. I've tried a bunch of ways to format the json data, but I can't quite get it to work. Do you have any tips on formatting multiple entries so that dict can read them? Thanks!

Jan M's icon

The file for a dict object can only contain one JSON object on the top level

{
   "myKey1" : ,
   "myKey2" : ,
}

But you can nest dicts inside dicts:

{
   "myKey1" : {  },
    "myKey2" : {  }
}

Of you can store them in arrays (as of Max 7):

{
   "allMyDicts" : [{},{},{}]
}

Jan M's icon

btw... check the examples inside dict help patch, you'll find everything there.

Adam's icon

Thanks Jan! I think I see my error. I checked the help files, but (to me) they weren't as clear as what you just wrote. :-)

Jan M's icon

The best in your case is to open the dict objects in the help file and take a look at the syntax. There you will find all possible formats.

Adam's icon

So I double checked all my work. Created dictionaries from scratch, checked formatting, etc. Still ran into problems. Then when I copy/pasted the data from my the txt/json file I was using strange errors appeared. Two of the keys had red quotes with black text. I'm not sure why this happened, but when I "fixed" them (by deleting and then re-writing exactly the same thing) it worked. So there must some other kind of problem. At least I'm getting closer.