[SHARING] parsing dictionaries from [maxurl]

    May 06 2018 | 2:41 am
    I would like to share with you the trifle that I recently wrote: it's a simple JavaScript mechanism for parsing dictionaries (especially from the [maxurl]). Useful if you need to process data obtained from sources communicating over various web-APIs (such as OpenWeather, Binance, Wagi, etc.).
    Recently there was some questions about related issues on the forum and most of the problems are connected to the dictionaries. Dictionaries are somewhow hard to handle for many Max users (mainly for those who do not use scripts). From the other hand, writing JS code handling dictionaries is, nearly always, boring and tedious (at least for me).
    So, my script is iterating over the dictionary created by the [maxurl], generates and broadcasts set of two-element lists (key name, value) from the dictionary. These lists can be easly handled in your patches using trivial objects, such as [route], etc.
    The script gives all keys unique names (naming schame is based on the original dictionary structure, so it's easy to understand) to avoid eventual problems with the keys with overlapping names nested in various parts of the dictionary.
    Btw. the script may serve also as an iterator for dictionaries created with different (than [maxurl]) methods - of course, in this case, it may require some sort of fixes, to adapt it to a specific context.

    • May 06 2018 | 2:02 pm
    • May 09 2018 | 2:41 pm
      Useful, thanks.
    • May 09 2018 | 4:14 pm
      Thanks Yaniki !
    • Aug 23 2018 | 4:39 pm
      Thank you so much for this!
    • Aug 23 2018 | 9:53 pm
      I'm glad you like it, friends.
      Btw. I've just corrected one detail. Nowadays it's much better to use https, than http.
    • Aug 24 2018 | 2:29 pm
      Very nice, Yaniki! But if you don't want to mess with JS, you can do the same just with just stock objects: pick "body", parse dict, pick your data.
    • Aug 24 2018 | 3:54 pm
      Sure, you can. The method depends on specific requirements and individual "style". I'm using scripting very intensely.
    • Aug 24 2018 | 4:34 pm
      @yaniki No prob! I read in your OP something about writing the code being boring and tedious, so... ;-) Peace!
    • Aug 24 2018 | 4:50 pm
      Haha... yes, this is very good... something like "let's do something boring again (and again)"
      I meant programming the same functionality (doesn't matter by coding or patching). So my script is kind of an universal solution (just parsing any dict without the need for hardcoding into patch values specific for the particular case).
      Of course, in most cases you have to hardcode particular references ("names" of values) in a different part of your patch anyway (which is probably a good example showing how coding and patching may be equivalent).
      Interesting topic...
    • Aug 24 2018 | 10:12 pm
      @yaniki Indeed interesting. So you parse the body of the server response and then send out any data as tagged values. But the problem arises when the data have different format (shape) than singular numbers or strings. JSON can have arbitrary structure, eg. an arrays of numbers mixed with embedded objects. This kind of data doesn't have a natural representation in Max message system. Hence I think there is no one-size-fits-all solution.
      Btw. There is JSON parser built in JS implementation. Here is my attempt to recreate your script using existing Max capability. A few times shorter and a few times faster. Not tested that much, but seems to work correctly.
      OK. Enough procrastinating for today, back to boring and tedious work ;-). Have a nice day!
    • Aug 25 2018 | 12:22 am
      O, that's a nice solution. Thanks for sharing.
    • Sep 08 2018 | 6:09 am
      great thread this one :)
    • Nov 06 2018 | 2:53 pm
      Friends is it possible to send data of one variable from one computer to another using the object maxurl?
    • Nov 06 2018 | 6:47 pm
      @Sonichel As far as I understand maxurl objects don't directly communicate with each other - they make requests to servers. Having that said, specially with max 8 and n4m, you should be able to create an overkill communication system with it ;)