Search code examples
jsonphotoshop-script

Parsing JSON in photoshop


I've recently found out that you can parse JSON files in photoshop using jamJSON

This is good news, but I've got a couple of stumbling blocks: For example, this is my JSON file

{
"YEAR" : {
  "longname" : "New Year"
 }
}

I can access it with

var jsObj = jamJSON.parse (jsonText, true);
alert (jsObj["YEAR"]["longname"]) // New Year

But since each file is going to be different and "YEAR" may be "FRUIT" or "GOLD" in another file. How do I access the data without knowing the first part of the object?


Solution

  • Although the answers are above are correct, I was getting confused between object and arrays (Easily done. I'm an artist, me) and was finally able to access the data using

     var jsObj = jamJSON.parse (jsonText, true);
    
      for (var key in jsObj) 
     {
       var obj = jsObj[key];
       alert (obj["longname"]);
     }