JSON data into Coll


    Apr 21 2022 | 9:31 am
    hi, I have not used javascript before, but have data that I want to use in JSON files. I can parse the files this way: function read(p) { memstr = ""; data = ""; maxchars = 800; path = p; var f = new File(path, "read"); f.open(); if (f.isopen) { while(f.position<f.eof) { memstr+=f.readstring(maxchars); } f.close(); } else { post("error\n"); } UI = JSON.parse(memstr); }
    function dump(){ for(i in UI){ for(j in UI[i]){ return("\n",i,j,UI[i][j]); } } } However, I cannot sort out how to get this data into a coll object. Any tips?
    Peter

    • Apr 22 2022 | 1:57 am
      check out the Dict JavaScript object docs. You can use setparse to read a JSON string and then push_to_coll. Or possibly just read the JSON file directly into the Dict.
    • Apr 22 2022 | 10:02 am
      OK I'll have a look - thanks!
    • Apr 22 2022 | 10:15 am
      Sorry - I really am a novice - where will I find those? I looked here: https://developer.mozilla.org/en-US/docs/Web/JavaScript but can't find Dict. P
    • Apr 22 2022 | 11:27 am
      https://docs.cycling74.com/max8/vignettes/javascriptinmax
    • Apr 22 2022 | 1:11 pm
      Great! thank you.
    • Apr 23 2022 | 10:16 am
      hey Tyler, done it! thanks so much - your hints made it possible.
      P