Skip to main content
Inspiring
January 28, 2022
Question

Read a JSON file in AE extendscript

  • January 28, 2022
  • 5 replies
  • 5166 views

Frustrated. Cant find a clear answer online.
I have a json file. I want my script to opn the file. Parse (eval?) it, and be able to spit out some info. 

Any help here, or even links is appreciated.

5 replies

Inspiring
February 4, 2022

Thanks all. The json2 method did the trick, i was not aware of that. Still a noob in a lot of ways. 🙂

Tomas B. aka Tom10
Inspiring
February 4, 2022

If the file you want to parse is relatively small (kb's of size), listed methods above are great. However, json2 library parser is extremely slow with bigger files.  As long as you are sure JSON is well formated and "safe", this is the fastest way in doing it, N times, literally:

 

 

var scriptFile = new File(filePath);
scriptFile.open('r');
var content = scriptFile.read();
scriptFile.close();
var dataObj = (new Function( "return " + content ))() ;

 

 
 
Mathias Moehl
Community Expert
Community Expert
February 4, 2022

That's an amazing tip, Tomas!
Do you happen to have a similar workaround for JSON.stringify()? This is also very slow in ExtendScript for big datastructures with long strings...

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
OussK
Community Expert
Community Expert
January 29, 2022

Try this tutorial from NT production, https://www.youtube.com/watch?v=mmFlGCEwrm8 

Mathias Moehl
Community Expert
Community Expert
January 29, 2022

See this tutorial how to use JSON data with Ae ExtendScript:

https://aescripts.com/learn/After-Effects-Scripting-JSON-Tutorial/

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Mylenium
Legend
January 28, 2022

I'm not clear what specifically you are asking. There is technically nothing to parse because it's already JavaScript that can be manipulated using regular functions. I'm not aware that there is a generic library or code snippet out there that would simply convert the node structure to arrays or whatever you may need, but clearly there's enough reference out there on how to deal with this on web frameworks like Node JS and the principles and methods could be adapted. Anything more specific will require much more detailed info on your part.

 

Mylenium