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

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

2.1K

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
LEGEND ,
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

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 ,
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/

 

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

Copy link to clipboard

Copied

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

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

 

 
 

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

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
Contributor ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

LATEST

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

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

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

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