• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Json footageItem

Participant ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

Just because someone has asked this question on another forum and I'm intrigued about this idea myself. When you put your JSON in the project panel. Is there a way to access the JSON data via script? So rather than using expressions, or a script to add an expression to a layer. Using something on the lines of app.project.item(index).sourceData.Name I've tried this and I know it doesn't work, but something on those lines to access that data via script. Is this possible?

TOPICS
Scripting

Views

699

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 27, 2018 Nov 27, 2018

Mathias,


Cheers for all your help. I don't know why, but it didn't like eval(jsonString), but if you use JSON.parse(jsonString). Worked first time.

So to clarify. To access the data, unless anyone has any better ways of doing it.

var w = new Window("palette","Test",undefined,{resizeable:true});

var btn2 = w.add("button",undefined,"submit");

var file = app.project.selection[0].file;    

file.open("r");     

var jsonString = file.read();    

file.close();

var Obj = JSON.parse(jsonString);

   

btn2.onClic

...

Votes

Translate

Translate
Community Expert ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

Yes, my free tool mamoworldJSON both reads and even creates such JSON files in the project panel:

mamoworldJSON - aescripts + aeplugins - aescripts.com

Something like that:

var file = of app.project.item(index).file;

file.open("r");

var jsonString = file.read();

file.close();

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

Sorry Mathias. I had it throw back an error as you had an of in yours, but I might be doing something wrong. Could you quickly glance and tell me why it's coming back with undefined. It's 2nd object in my panel.

So I changed that and in my Json, my first line is "Name": "Mexico", For testing purposes I just want to see it alert the text so I know it's working before I spend my time applying it to something else. I know it'll be something stupid.

var w = new Window("palette","Test",undefined,{resizeable:true});

var btn2 = w.add("button",undefined,"submit");

var file = app.project.item(2).file;

file.open("r"); 

var jsonString = file.read();

file.close();

btn2.onClick = function(){       

alert(jsonString.Name);    

};

w.show();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

If you select the json file in the project panel, does it work with

app.project.selection[0].file

?

Then you can find the correct id with

app.project.selection[0].id

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

It came back with the number 12. I have no idea what that means hahahaha

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

but using (jsonString[0].Name). It still comes back with undefined

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

jsonString is just a string. To turn it into a json object you need to parse it.

var jsonObject = eval(jsonString);

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

I'm really sorry Mathias. I'm still not quite understanding this I get what you mean about converting the string into an object. Looking at other forums quickly. It seems to make sense. But

Adapting what you're suggesting I tried

  1. var w = new Window("palette","Test",undefined,{resizeable:true});  
  2. var btn2 = w.add("button",undefined,"submit"); 
  3.  
  4. var file = app.project.item(2).file;  
  5. file.open("r");   
  6. var jsonString = file.read();  
  7. file.close();
  8. var var jsonObject = eval(jsonString); 
  9.  
  10. btn2.onClick = function(){         
  11. alert(jsonObject[0].Name); (I also tried (jsonObject.Name)      
  12. };  
  13. w.show();

This didn't work. It came back with an error disliking my Json (Although I know the Json is fine)

Then I adapted something that works if you put the Json in the script. It worked with the str in the script. But this didn't work either.

var w = new Window("palette","Test",undefined,{resizeable:true});

var btn2 = w.add("button",undefined,"submit");

var str = app.project.selection[0].file; 

var jsonObject = eval(str);

btn2.onClick = function(){

        alert(jsonObject.Name);

    };

var jsonObject = eval(str);

btn2.onClick = function(){

        alert(jsonObject.Name);

    };

w.show();

It one of those things that makes 75% sense, but the 25% is what I'm failing to understand.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

LATEST

Mathias,


Cheers for all your help. I don't know why, but it didn't like eval(jsonString), but if you use JSON.parse(jsonString). Worked first time.

So to clarify. To access the data, unless anyone has any better ways of doing it.

var w = new Window("palette","Test",undefined,{resizeable:true});

var btn2 = w.add("button",undefined,"submit");

var file = app.project.selection[0].file;    

file.open("r");     

var jsonString = file.read();    

file.close();

var Obj = JSON.parse(jsonString);

   

btn2.onClick = function(){           

alert(Obj.Name);

}; 

w.show();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines