Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions [Problem] Access multiple JSON files with RegEx and dynamically calculate y-Axis

  • [Problem] Access multiple JSON files with RegEx and dynamically calculate y-Axis

    Posted by Leonie Wercker on January 10, 2021 at 5:18 pm

    I have multiple JSON files that I need to animate – each based on the same template.

    The animation is a normal coordinate system and values for the x and y axis are nested in the JSON files. The graphic below shows the template and the layout for two different JSON files.

    The problem is that the number of values for the x axis varies; meaning some JSON files only have 3 values, others 5, others 7, etc.

    However, I want to have the x axis values in each animation evenly/symmetrically distributed on the x axis (the space in between the two red lines).

    My first attempt was to count how many x values are in the JSON file and then distribute them along the x axis by dividing the pixel length of the axis by the number of values. But I failed to succeed here (How to count nest JSON values with expressions).

    My other thought was to fix a first null and a last null and have all other values distributed in between them. No idea though how to do this with expressions.

    Would anybody be able to help?

    Leonie Wercker replied 5 years, 5 months ago 4 Members · 13 Replies
  • 13 Replies
  • Andrei Popa

    January 12, 2021 at 8:11 am

    Your graph is not here.

    I also think it would help if you could post the content of a json file to see exactly how that data is.

  • Leonie Wercker

    January 13, 2021 at 6:32 pm

    this is the project file, a picture of the issue and the data file (you have to rename it to .json as json files cannot be uploaded here)

    thanks!!!

  • Filip Vandueren

    January 14, 2021 at 9:02 am

    The JSON wasn’t added unfortunately

  • Leonie Wercker

    January 14, 2021 at 8:29 pm

    i tried but json files are not possible to upload. so i renamed it to .txt file. but this wasnt uploaded either. can i contact you directly here?

  • Andrei Popa

    January 15, 2021 at 9:34 am

    Can you share a cloud folder in which you got these 2 files?

  • Leonie Wercker

    January 18, 2021 at 4:12 pm

    There are both files in this dropbbox folder:

    https://www.dropbox.com/sh/a1lgjlxes868qwj/AAA5PxN8xCVS_8XT7O2sTJGha?dl=0

    I am stuck with this:

    The animation works for this JSON file. However, I have multiple other JSON files – and these vary with regards to the datapoints on the x axis.
    Thus, I am looking for an expression that automatically checks, how many datapoints are in each JSON file when loaded and distributes them evenly/symmetrically along the x-axis.

    Would any of you have an idea for that?

  • Tomas Bumbulevičius

    January 23, 2021 at 9:45 pm

    Hey Leonie, here are some thoughts based on your files:

    1. If I understood correctly, your initial ideal will won’t work with dynamic number of data points, UNLESS you make sure there are that much layers created in the “Graph” comp. Meaning, if you do it now with more than 12 values – it won’t work (I guess you are aware of this, but just to highlight an issue of this approach)

    2. In “Graph” comp, assuming your comp structure isn’t going to change, define seriesrating[X] as seriesrating[index+1] (as first layer in a list starts with index of 1, but arrays has indexing from 0). You won’t need to manually update it.

    3. Now with above in mind, you should add a check which evaluates maximum seriesrating index in a .json, to not overcome maximum. This could be done in a control layer at the bottom of the comp, on in other place. Since you are approaching this Seasons-based, I would suggest collecting objects in array, which has matching “Season” index. Then – getting length of that objects array.

    4. When number of season-items will be clear, you can interpolate X’s distances based on that number, and your comp/design width. However, 1st point must be taken into account for this.

    5. I would suggest to not have contants attached to variables like “-600” and “900” – link them through Sliders, to have dynamically adjustable design.

    Hope any of these helps to figure it out!

  • Leonie Wercker

    February 20, 2021 at 1:25 pm

    thanks for that helpful information. I was able to process this a little further…but still having a problem.

    This is my code from the null object layer (and I put in the maximum null objects layers as needed.

    1) var data = footage(“Homeland.json”).sourceData; // this gets the data from the JSON file

    2) var numberOfEntries = data.length; // this checks how many data items are there in the JSON file

    3) var myIndex = thisLayer.index-1; // this assigns the corresponding number to this null object layer (this is where the after effects / JSON logic needs to be addressed: e.g. layer 3 receives datapoint 2 (since data points are counted starting at 0)

    4) if(myIndex >= numberOfEntries) myIndex = numberOfEntries-1; // this ensures that the null objects that are great than the count of datapoints within the JSON files act as the last correct datapoint

    5) var myXPosition = linear(myIndex,0,numberOfEntries-1, 250, 1700); // this plots the counted fully layers across the length of the x-axis (first entry is at X=250, last one at X=1700)

    I have a problem with line 4 as I don’t want the remaining datapoints not plotted as the last known value before, but to be NOT plotted at all.

    so frankly speaking, this happens now:

    – count JSON file how many datapoints there are
    – plot all counted datapoints according to their values
    – plot those datapoints that are above the count like the last one counted

    e.g. counted 12 values, maximum is 20 values, so a surplus of 8 values,
    these 8 values become plotted with the value of the 12th value

    what I want to happen:

    – count JSON file how many datapoints there are
    – plot all counted datapoints according to their values
    – only plot counted values
    – delete/ignore surplus 8 values

    thanks for any ideas on this 🙂

  • Filip Vandueren

    February 20, 2021 at 1:27 pm

    Maybe you can simply set the opacity of the surplus layers to 0 ?

  • Leonie Wercker

    February 20, 2021 at 1:37 pm

    but then they are still plotted:

    12 regular values plotted + 8 values with less opacity plotted = 20 values plotted across the x-axis

    but I just need to plot the 12 regular values plotted.

Page 1 of 2

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