Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions AE Scripting: JSX parsing JSON file already in Project

  • AE Scripting: JSX parsing JSON file already in Project

    Posted by Quba Michalski on November 20, 2018 at 12:16 am

    Hey,

    I am working on a project which requires me to automate creation of comps and layers based on a JSON file. I managed to successfully write a JSX script that reads an external JSON file and does the job, but I was wondering: Is there a way to JSX-parse a JSON file that has already been imported as footage? All my attempts so far result in json2.js library returning errors…

    Quba Michalski
    qubahq.com

    Truckee Lynch replied 5 years, 8 months ago 3 Members · 9 Replies
  • 9 Replies
  • Scott Mcgee

    November 23, 2018 at 1:12 pm

    Unsure what you are trying to do, but if you are in cc2018 or higher.

    This is an example of how you access the data from a JSON file that you bring into after effects.

    txt = footage(“TEST.json”).sourceData;
    txt.Name

    but as for json2.js that’s a script job, as far as I’m aware you can’t do that in after effects.

    Hope that helps

  • Quba Michalski

    November 24, 2018 at 3:25 am

    What I am trying to do cannot be achieved with expressions. I am looking to change the name of the composition. More precisely – to duplicate master composition hundreds of times, and give each new comp a name from a JSON file.

    Again – I have no problem doing it by reading an external file, but wondering if it could be achieved with a JSON already imported as footage.

    Quba Michalski
    qubahq.com

  • Scott Mcgee

    November 24, 2018 at 9:02 am

    Ah, in that case.

    No.

    Alterations to comp and layer names can only be achieved via script. Or as far as I’m aware, but I’m pretty confident that can only be done by script.

  • Quba Michalski

    November 25, 2018 at 12:04 am

    Once again – my question was not whether expressions can change the comp name.

    My question was: Can JSX Script (File > Scripts) read a JSON file already imported into as a footage – and if so: how?

    Quba Michalski
    qubahq.com

  • Scott Mcgee

    November 26, 2018 at 9:37 am

    Completely sorry.

    With it being such a new feature being able to import a json file as footage. I honestly don’t know.

    One would argue that if there was a way to do it via expression. That you should be able to definitely do it via script.

    Sorry for misunderstanding, but I think with it being a new feature importing json as footage. It’s going to be a case of trial and error.

    Mathias Moehl on adobe forums tends to be pretty good with that type of thing. If you want to try there, but all I’m find is expressions, or scripts that add expressions to layers to access the information.

  • Scott Mcgee

    November 27, 2018 at 9:00 am

    Quba

    I cracked it, this will work.

    You’ll have to adapt to get it to work for yourself. I just wanted it to alert an object in my Json to make sure it worked.

    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();

    Mathias helped me, but it didn’t like eval, but using JSON.parse fixed it.

    So. After all that. Yes it can be done.

  • Truckee Lynch

    August 21, 2020 at 11:37 pm

    This solution uses the file system to grab that JSON file. Was it ever determined if extendscript can access an existing .json footage item already imported into the project window of an existing project? Expressions can do this. Loading the file seems like additional work and ideally, I’d be able to parse it where it is.

  • Scott Mcgee

    August 24, 2020 at 11:01 am

    I don’t think that is possible. Even using the expression function, AE has inbuilt support to parse it in the background. However I don’t know if that is done when importing. If you trying and access it in the project file like so


    app.project.selection[0].file;
    alert(file);

    you get the filePath and if you try this like a json file

    app.project.selection[0].file;
    alert(file[0]);

    you get undefined. So I assume that AE does something in the background that you just can’t do with extend script and extend script doesn’t have the ability to natively read Json.

    However if your json file is in the timeline you can access that data using extend script easily by accessing the properties. Tried to go backwards from there, but kept getting undefined. So unless anyone jumps in, unfortunately the script I wrote a few years back is the only way to still access json from the project window.

    It just allows you to skip selecting a file from a folder or having the script remember the file pat. So there is some benefit.

    I prefer using script to expressions, purely because it when it comes to exporting. It is so much faster. I know AE is getting better, but when you have hundreds of expressions. It slows down export time dramatically.

  • Truckee Lynch

    August 24, 2020 at 8:49 pm

    Thanks for the response! I was naive in assuming all methods and features that are accessible in expressions are also accessible via script. Alas.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy