Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for json-file

  • Expression for json-file

    Posted by Johannes Jonasson on July 3, 2020 at 9:30 am

    Hi,

    I’ve never used a .json file in an expression before. This is the data, and I’ve downloaded the file to my computer and imported it to After Effects:
    https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/owid-covid-data.json

    I want to make a list with all countries, and I want the list to change depending on the variable total_deaths_per_million for every date.

    I realise my expression is far off. My first problem is that I can’t work out how I get the right variable. With the expression I’ve tried I get the error message “Couldn’t turn result into numeric value”.

    First of all, is it even possible to create an expression that works like I want it to? Anyone have any good advices?

    Kind regards

    footage("owid-covid-data.json").sourceData;

    p1="AFG"[1].total_deaths_per_million;
    p2="AFG"[2].total_deaths_per_million;

    exDepth = 360

    min = 0;
    max = 1000;

    startVal = ((p1 - min)/max)*exDepth;
    endVal = (p2/max)*exDepth;

    z = ease(time, 1, 4, startVal, endVal);

    x=640;
    y=z;

    [x,y];

    Tomas Bumbulevičius replied 6 years, 1 month ago 3 Members · 18 Replies
  • 18 Replies
  • Filip Vandueren

    July 3, 2020 at 12:25 pm

    You want to make a list of countries…so what does this expression have to return ?
    a textSource with countries ordered by total_deaths_per_million ?

  • Johannes Jonasson

    July 3, 2020 at 12:38 pm

    Yes, that is what I am trying to do. But I also want the countries to change order depending on the date.

  • Filip Vandueren

    July 3, 2020 at 1:26 pm

    This works, surprisingly well and fast given the huge dataset…

    date = "2020-05-11";

    data = footage("owid-covid-data.json").sourceData;
    countries = Object.keys(data);

    results=[];
    for (c=0; c element.date === date).total_deaths_per_million;
    } catch(e) {
    tdpm=0;
    }
    results.push( [data[countries[c]]["location"], tdpm] );
    }

    results.sort( (a,b) => b[1]-a[1] );
    results.reduce( ( acc, cur ) => acc + cur[0]+"—"+cur[1]+"\r", "");

  • Filip Vandueren

    July 3, 2020 at 1:34 pm

    Sorry, problems with the <-symbol in the previous post…

    date = "2020-05-11";

    data = footage("owid-covid-data.json").sourceData;
    countries = Object.keys(data);

    results=[];
    for (c=0; c<countries.length; c++) {
    try{
    tdpm= data[countries[c]]["data"].find( element => element.date === date).total_deaths_per_million;
    } catch(e) {
    tdpm=0;
    }
    results.push( [data[countries[c]]["location"], tdpm] );
    }

    results.sort( (a,b) => b[1]-a[1] );
    results.reduce( ( acc, cur ) => acc + cur[0]+"—"+cur[1]+"\r", "");

  • Johannes Jonasson

    July 3, 2020 at 2:01 pm

    Tried it now, but I dont’t seem to get it correct (Sorry, I’m a total newbie when it comes to this).

    I copied your expression into Expression: Source Text in an empty text layer. But I do not get any text out of it. So what am I doing wrong here?

  • Filip Vandueren

    July 3, 2020 at 2:04 pm

    Did you try the second post ?

    Does the name of the Footage-file match yours ?

    Is the Javascript Engine in Project Settings set to “Javascript”, not “Extendscript Legacy”

    Are you getting an empty layer and no error, or an error ?

  • Johannes Jonasson

    July 3, 2020 at 2:12 pm

    Yes, tried the second post, and the footage-file name is the same as yours. Also checked the Javascript engine at it was set to “Javascript”.

    I get an empty layer and no error.

    Really appreciate your help by the way!

  • Johannes Jonasson

    July 3, 2020 at 2:15 pm

    Tried it again and now I got a list of text.
    But on every row it says “undefined–0″….

  • Johannes Jonasson

    July 3, 2020 at 2:28 pm

    Update! Now it seems to be working perfectly, I just had to reload the footage file.

    Thank you very much for your help! Was worth alot!

  • Filip Vandueren

    July 3, 2020 at 4:04 pm

    Let me know how it turns out! Or if you need more help.

Page 1 of 2

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