ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How do you look up line numbers in a JSON file?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Austin Reddington
How do you look up line numbers in a JSON file?
on Aug 30, 2019 at 6:59:36 pm

Hey Everyone,

I'm new here and I am trying something different in After Effects. I've found several helpful threads here but I still can't seem to solve this problem.

I have a JSON file with a list of Teams, Mascots, and Logos. I want to type in a team name in one layer and have another text layer autofill with the mascot. basically I need to be able to find the line number of the matching Team so that I can output the corresponding Mascot.

I've been trying to adapt this thread here: https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=4026...
but to be honest I really don't know what I'm doing (As you can probably tell from my code ☺ ). Any feedback or tips would be greatly appreciated!

Thanks!

Austin

json=eval(footage("TeamInfo.json").sourceText);

lookup={};
for (i in json) {
line=json[i];
LineNumber = line.TeamName;
lookup[LineNumber] = {TEAM: line.team, MASCOT: line.mascot, LOGO: line.logo};
}

// get the Team Name
TeamName=thisComp.layer("Team").text.sourceText;

LineNumber = TeamName;

lookup[LineNumber].mascot;


Return to posts index

Tomas Bumbulevičius
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 4:08:31 pm

Hey Austin, just to make sure, could you please share .json's object structure of few 'items'? That way it would be clear whether its an object of objects, or array of objects. In both scenarios access of the object key values is different. Cheers!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Austin Reddington
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 4:46:42 pm

Hey Thomas, thanks for your reply!

Sorry, I definitely should have included that. Here is what my .JSON looks like:

{
"TEAM": "Abilene Chr",
"MASCOT": "Wildcats",
"LOGO": "ABILENE_CHRISTIAN"
},
{
"TEAM": "Air Force",
"MASCOT": "Falcons",
"LOGO": "AIR_FORCE"
},

I can change this structure if it makes it any easier. Please let me know if you have any suggestions.

Thanks!


Return to posts index


Alex Printz
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 5:05:23 pm

I think if you create object names prior to your properties of that object, you should be able to easily call them (scrub through a slider, etc.):

"1" : {
"TEAM": "Abilene Chr",
"MASCOT": "Wildcats",
"LOGO": "ABILENE_CHRISTIAN"
},
"2" : {
"TEAM": "Air Force",
"MASCOT": "Falcons",
"LOGO": "AIR_FORCE"
},

then you just call it like this:

jsonData.1.LOGO

Alex Printz
Mograph Designer


Return to posts index

Austin Reddington
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 5:34:42 pm

Thanks Alex!

I figured out a way to call up the data that I want. What I am really looking for is to type in the name of the team and have the expression pull the corresponding mascot name from the list. Like this:

- I type in "Air Force" to a text layer.
- Another text layer reads that input and matches TEAM: "Air Force" to MASCOT: "Falcons" and then outputs the text "Falcons."
- Basically I am looking for this number - jsonData.[find this number].MASCOT based off of a text layer.

Is that possible? Please let me know if you have any ideas.

Thanks!!


Return to posts index

Alex Printz
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 6:21:52 pm

Yeah, all you have to do is this:

AbileneChr{
"TEAM": "Abilene Chr",
"MASCOT": "Wildcats",
"LOGO": "ABILENE_CHRISTIAN"
},
AirForce{
"TEAM": "Air Force",
"MASCOT": "Falcons",
"LOGO": "AIR_FORCE"
},

jsonData.AbileneChr.MASCOT

just make each category the team name without spaces. Format however you want. You could either make your scripts parse out and space characters, or just don't type them into your text box when you tell it what to grab.

Alex Printz
Mograph Designer


Return to posts index


Austin Reddington
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 6:28:35 pm

Brilliant!!!! Thanks, Alex! it's so simple but I think it will work!


Return to posts index

Alex Printz
Re: How do you look up line numbers in a JSON file?
on Sep 3, 2019 at 6:29:12 pm

"AbileneChr" : {
"TEAM": "Abilene Chr",
"MASCOT": "Wildcats",
"LOGO": "ABILENE_CHRISTIAN"
},
"AirForce":{
"TEAM": "Air Force",
"MASCOT": "Falcons",
"LOGO": "AIR_FORCE"
},

I meant.

I don't think you can create a loop through a json to look for items and compare by names; JSON is an unordered property, so it needs to be called directly through a string. There is no index count to go through.

Alex Printz
Mograph Designer


Return to posts index

Austin Reddington
Re: How do you look up line numbers in a JSON file?
on Sep 4, 2019 at 2:32:39 pm

So I tried it, but After Effects doesn't recognize it as a proper JSON file. It wants me to convert it to a JSX file. Is there a way I can do that properly in JSON format?


Return to posts index


Alex Printz
Re: How do you look up line numbers in a JSON file?
on Sep 4, 2019 at 9:12:00 pm

Try following something like this, it's been a while since I made a JSON from scratch:

https://lesterbanks.com/2018/09/create-json-file-ae/

Alex Printz
Mograph Designer


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]