Parsing JSON file

Peter Williams's icon

Hello,

I struggling with trying to parse a JSON file created by pattrstorage.

Firstly I should describe what I am trying to achieve. I am using pattrstorage to store the values of various integer number boxes and am currently opening the 'storagewindow' to allow me to see the values. This is great, but I'd like to be able to swap the two axis. So instead of displaying the slot id and name on the x axis and the scripting names on the y axis, I want to view the data the other way round (x axis with scripting name and y axis with slot id).

Hence trying to parse the JSON file that was created by pattrstorage to extract the information and display in my preferred format. The data all relates to lighting cues and as such I would want the current cue highlighted with the previous 3 to 4 cues aboves and the next 3 to 4 cues below, and interpret some of that data to display colours rather than just rgb 0-255 values.

Hopefully someone can point me in the right direction of how to firstly read the JSON file in max and then extract the data so that I can display it in a max patch. Ideally a maxpatch example.

Floating Point's icon

I've never done this (wrt pattrstorage file), but you should be able to read it in to a dict object. You might need to use some javascript to do it, as outlined in this thread:
https://cycling74.com/forums/json-to-dict
although this might be a little out of date (max 5 or 6?).

I think there is this way now (Max 6 or 7?):
var jsonString = JSON.stringify(jsonObjectFromSomewhere);
var d = new Dict("dict_name");
d.parse(jsonString);

where "dict_name" is the name of the existing [dict] object you want to write to, and "jsonObjectFromSomewhere" is the json object you want to put in the dict.
from this thread: https://cycling74.com/forums/push-raw-json-from-node-script-to-a-dict

the same thread also recommends a way of doing it in max 8 using node.script
once it's in a dict you can then manipulate it any way you like within max.