Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How do you look up line numbers in a JSON file?

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

    Posted by Austin Reddington on August 30, 2019 at 6:59 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=40261&univpostid=40261&pview=t
    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;

    Alex Printz replied 7 years ago 3 Members · 9 Replies
  • 9 Replies
  • Tomas Bumbulevičius

    September 3, 2019 at 4:08 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

  • Austin Reddington

    September 3, 2019 at 4:46 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!

  • Alex Printz

    September 3, 2019 at 5:05 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

  • Austin Reddington

    September 3, 2019 at 5:34 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!!

  • Alex Printz

    September 3, 2019 at 6:21 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

  • Austin Reddington

    September 3, 2019 at 6:28 pm

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

  • Alex Printz

    September 3, 2019 at 6:29 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

  • Austin Reddington

    September 4, 2019 at 2:32 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?

  • Alex Printz

    September 4, 2019 at 9:12 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy