hierarchical JSON -> dict

John J.A. Jannone's icon

How can I get JSON like this into a dict?

"[{\"title\":\"512-depth-ema.safetensors\",\"model_name\":\"512-depth-ema\",\"hash\":null,\"sha256\":null,\"filename\":\"/Users/johnjannone/stable-diffusion-webui/models/Stable-diffusion/512-depth-ema.safetensors\",\"config\":null},{\"title\":\"v2-1_768-ema-pruned.safetensors [dcd690123c]\",\"model_name\":\"v2-1_768-ema-pruned\",\"hash\":\"dcd690123c\",\"sha256\":\"dcd690123cfc64383981a31d955694f6acf2072a80537fdb612c8e58ec87a8ac\",\"filename\":\"/Users/johnjannone/stable-diffusion-webui/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors\",\"config\":null}]"

I tried several approaches, and eventually made this Max monstrosity to get something that worked (attached), but it seems there's got to be an easier way...

dict-test.maxpat
Max Patch

tyler mazaika's icon

Input of arrays of stuff is a pain. But life can be much easier if you can do JSON handling in javascript...

Max Patch
Copy patch and select New From Clipboard in Max.

John J.A. Jannone's icon

That's great - thank you Tyler! I hope the max dict suite will eventually handle hierarchical JSON better, but this will do the trick for now, and I'll study it as well :)