Read a JSON file in AE extendscript
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
See this tutorial how to use JSON data with Ae ExtendScript:
https://aescripts.com/learn/After-Effects-Scripting-JSON-Tutorial/
Copy link to clipboard
Copied
Try this tutorial from NT production, https://www.youtube.com/watch?v=mmFlGCEwrm8
Copy link to clipboard
Copied
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 ))() ;
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
amazing!
This has changed my life, Tomas I can't thank you enough! I was trying to parse JSON files that were taking 10 minutes, now they're taking 2 seconds...
Copy link to clipboard
Copied
Thanks all. The json2 method did the trick, i was not aware of that. Still a noob in a lot of ways. 🙂

