Read a JSON file in AE extendscript

Explorer ,
Jan 27, 2022 Jan 27, 2022

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.

TOPICS
Scripting

Views

116

Likes

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
Adobe Community Professional ,
Jan 28, 2022 Jan 28, 2022

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

Likes

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
Adobe Community Professional ,
Jan 29, 2022 Jan 29, 2022

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/

 

Likes

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
Adobe Community Professional ,
Jan 29, 2022 Jan 29, 2022

Copy link to clipboard

Copied

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

Likes

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 ,
Feb 03, 2022 Feb 03, 2022

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

 

 
 

Likes

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
Adobe Community Professional ,
Feb 04, 2022 Feb 04, 2022

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...

Likes

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
Explorer ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

LATEST

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

Likes

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