Activity › Forums › Adobe After Effects Expressions › Expression for json-file
-
Johannes Jonasson
July 6, 2020 at 9:09 amAh, a problem occured. I have to change the data set to WHO:s data set.
https://covid19.who.int/?gclid=Cj0KCQjwl4v4BRDaARIsAFjATPkGlMd_GDm_2iQ96kJ5GqR-L6eO5VrTurcCH-vE5C5HUNaq_fw9lgwaAgkXEALw_wcB(Deaths > “Download map data”).
But then i get an error message.
“TypeError: Cannot convert undefined or null to object
countries = Object.keys(data);“.And I guess I have to change pretty much more in the expression later on? But I have no clue tbh
-
Filip Vandueren
July 6, 2020 at 9:28 amOf course, you have to know the structure of the JSON to know how to retrieve data from it.
The example I coded was made especially for the dataset you referred to. -
Filip Vandueren
July 6, 2020 at 11:10 amOuch, it’s not even a JSON this time I see.
I’ve found that working with CSV of this large set is paaaaainfully slow.
It’s much much faster to just look at the sourceText of the csv and do some parsing ourselves with regular expressions working on the strings:
f=footage("WHO-COVID-19-global-data.csv");
st=f.sourceText.replace(/(,"[^"]*),([^"]*")/g, "$1-$2");
// a first replace() to get rid of pesky comma's inside of region namesdate ="2020-05-01";
re = new RegExp(date+".*","g");// match strings (lines) starting with our date
matches = st.match(re);// string split into array
matches=matches.map( (r) => r.split(",") );// only keep element 3 and 7 (country name, daily deaths)
matches=matches.map( (r) => [r[2], r[6]]);// reverse sort by 2nd element (deaths)
matches.sort( (a,b) => b[1]-a[1] );// reduce array into a string
matches.reduce( ( acc, cur ) => acc + cur[0]+"—"+cur[1]+"\r", "");
-
Johannes Jonasson
July 6, 2020 at 12:51 pmWow! This works perfectly!
Now I have two new questions;
Is there some way to change this data each second with an expression? So like first second shows 1st of january, and second 15 shows 15th of january? I’ve been trying this with multiple “if” statements, but it is alot of work to do it by hand.And if so, is it then possible to make the countries change place smoothly? Whit this expression they just pop up at a different place, but I want the change of position to be visible. So that when one country gets a higher value you can see it move up along the list.
-
Filip Vandueren
July 6, 2020 at 12:57 pmGet the date from the sourceText of a different layer.
You can keyframe the dates manually, or it’s easy enough to write an expression to increase the date every second.
Your second point: yes this is possible, but not (easy) in 1 text-layer.
Are you doing this for non-profit. Because I don’t want to be building this whole thing for someone else to reap the benefits if you get what I mean.
-
Johannes Jonasson
July 6, 2020 at 1:24 pmTotally understand. But I’m trying to learn more about expressions during the summer, and thought this would be an interesting animation to put on like YouTube (as a hobby).
-
Filip Vandueren
July 6, 2020 at 1:37 pmOk, I thought you had a client because you mentioned you now have to use another dataset.
Anyway; is it going to stay a list of text and numbers , or are there going to be graphs, color-coding,… maps,…
best to plan a bit ahead and design a mock-up of what you want before trying to make it data-driven. -
Tomas Bumbulevičius
July 11, 2020 at 11:06 amFilip has a good point here – prior planning is needed, in order to make it happen in a more clear way, with less friction and back and forth. Yet solely on my previous experiences in this field of data-driven animations, making them comparable through expressions is an overkill – too slow, too limited. While it has benefits of instant data updates when updating the file – its not beneficial enough IMO.
Nor it provides enough flexibility and easiness of customisation. My vote would be to go scripting instead, but of course – learning how to achieve similar through expressions is a good path to familiarise with expressions world!
Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH
Reply to this Discussion! Login or Sign Up