Jan 07 2019 | 10:17 pm
    Hello, I'm a begginer in the dictionary and Javascript worlds. I have a patch that can download a json file from a web site into dictionary with a [maxurl]. So far all goes well and I can view in my [dict.view] object the correct structure of my imported json file (see attached image). The problem is that I can't query the values of noise (the average key for example). If I send a "get status" message I get the value of status alright, but when I send dictionary a "get average" or "get noise::average" I get an error message saying "index out of range for key noise" ! I can't seem to find the right syntax for dictionary. Can anyone tell me how can I get access to the noise values, please !

    • Jan 08 2019 | 7:31 pm
      Can you attach the dict content as txt file to your post? Looks like it is a nested dict and that's why your query doesn't work.
    • Jan 08 2019 | 8:14 pm
      Hi Martin, here is a txt file of the dict content and another in .json format just in case. What is a nested dict? {"help": "https://portal.opendata.dk/api/3/action/help_show?name=datastore_search_sql", "success": true, "result": {"records": [{"noise": {"max": 79, "average": 66.5, "min": 55.3}, "PM2.5": 0, "PM10": 0}], "fields": [{"type": "json", "id": "noise"}, {"type": "int4", "id": "PM10"}, {"type": "int4", "id": "PM2.5"}], "sql": "SELECT noise, \"PM10\", \"PM2.5\" from \"7e85ea85-3bde-4dbf-944b-0360c6c47e3b\" WHERE deviceid = '2c002e000f47373334363431' ORDER BY published_at DESC limit 1"}
    • Jan 08 2019 | 9:48 pm
      Well, I think patchers are not really a good solution for query of nested dicts. I think it's better to go for a javascript solution for this (see e.g. helpfile of [dict]). The attached patch gives the value you want, but the approach is not sufficiently generic.
      Nested dict means dict inside a dict. I don't know if this is the common term, but in other programming languages there is a similar concept or data type called nested lists or struct, which means that a certain structure can be embedded in child nodes that look similar or the same as the parent node structure.
      I think there are better solutions to your problem than my patcher. For your understanding it might help to note the following. Every time a query gets a dictionary as result like in your screenshot dictionary u926001544 use a print object to see how many dicts were output. The names of these dicts are automatically created during runtime. You could build a patcher that takes all of these dicts and performs queries inside of each of them. But I think javascript is more convenient.
    • Jan 09 2019 | 6:46 pm
      Thanks a lot, it works fine for me. I don't have time to learn Javascript for the installation I am doing actually. I think I will use json files that have only one child node for every nested dictionary. Just one question though, the :: sign is the syntaxe indicating the path of the nested dictionary right? Cheers
    • Jan 10 2019 | 10:52 pm
      Hello WBREIDI,
      finally found the syntax for directly accessing these nested or array like structures.
    • Jan 11 2019 | 7:21 pm
      Hello Martin, I can't acces the patch !
    • Jan 11 2019 | 8:12 pm
      Did you scroll down a bit? Objects keep their position in patch even if you only copy a part from a patcher.
    • Jan 12 2019 | 12:03 pm
      When I click on copy patcher I get a blank page with the title Dictionnaries, a few thumbnails and that's all ! I can't even send a reply from that page. It is very strange, I wonder why?
    • Jan 12 2019 | 2:47 pm
      Happy New Year all ! same here with Firefox and Thunderbird from yesterday... Opening the page in Safari works michel
    • Jan 12 2019 | 9:37 pm
    • Jan 13 2019 | 11:11 am
      ...back to my computer. I don't know why the compressed patch is not accessible. At my computer it works with Safari and also with Chrome on Android phone. Just in case it helps I attached the patcher (slightly modified version) as maxpat file.
    • Jan 13 2019 | 4:38 pm
      Hello Martin, I used Safari instead of Firefox and it works. The patch works too. I can go as far as two nested dictionaries but not 3 (index out of range for "field" 3), I can do with just two nested dictionaries, that's fine. Thanks a lot.