Skip to main content
Gregor@philoro
Participating Frequently
May 16, 2022
Answered

Length of JSON File / Nr. of DataSets (Expression)

  • May 16, 2022
  • 2 replies
  • 944 views

Hi!

 

I'm currently working on a data driven chart generator. I'm all good with importing, parsing and using JSON Data, but there is one thing I can't get to work:

 

My JSON Files have a changing numbers of data sets. All I need to know is how much of them are there. So one day this could be only 3 data sets long:

 

 

While on other days there could be 180 or more. I tried to check the sourceData for its Array Length, the property Count of the JSON in the Timeline...nothing seems to work and give me this one number I need.

This topic has been closed for replies.
Correct answer Dan Ebberts

All engines Stop! I've found a solution! extendScript to the rescue:

 

app.project.item(1).layer(1)("Data")(1).numProperties

 

does the trick 🙂 As my system is a combined extendScript/expression solution thats a way I can go 🙂


I think this works:

data = footage("csvjson.json").sourceData;
data.length

2 replies

Roland Kahlenberg
Legend
May 16, 2022

Unfortunately, the documentation for JSON is rather thin, IMO - https://helpx.adobe.com/after-effects/using/expression-language-reference.html

You'll most likely do a loop until you hit an error. So, a try...catch routine should be what you'll like be employing.

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Participant
May 16, 2022

Thanks, I was afraid so.

Participant
May 16, 2022

All engines Stop! I've found a solution! extendScript to the rescue:

 

app.project.item(1).layer(1)("Data")(1).numProperties

 

does the trick 🙂 As my system is a combined extendScript/expression solution thats a way I can go 🙂

Mylenium
Legend
May 16, 2022

Without any idea about the formatting of the data and what expressions you used nobody can tell you much. There's a good chance you may simmply need to write soem regEx/ string processing code to filter out the surrounding code/ tags from the actual data.

 

Mylenium

Gregor@philoro
Participating Frequently
May 16, 2022

Hi Mylenium,

 

My Datasets look like this (at the end of the posting). I know that I could just count substrings via brackets from a sourceText output e.g., but isn't here a more sophisticted way? Something like a "numItems" or "numKeys" Method e.g?

 

This is my Expression so far for the positioning of the data points:

 

----

var myMultiplier = comp("CHART_SETUP").layer("Setup").effect("Multiplier")("Slider").value;
var myDistance = comp("CHART_SETUP").layer("Setup").effect("Distance")("Slider").value;

 

var myX = myDistance*thisLayer.index;
var endHight = 1080-parseInt(footage("csvjson.json").dataValue([thisLayer.index-1,7])*myMultiplier);
value = [myX,endHight];

----

 

So I'm telling it "take Dataset Nr (Index-1), Element 7). That works fine. I'd like to create "numKeys" times this Layer for an automated creation of  my chart (using an extendScript duplicator and layer reorder). Hope it's clearer now, what my intentions are.

 

[
{
"Date": "06:00:00 16-May-2022",
"High (kg)": 58166.33,
"Low (kg)": 58096.96,
"Close (kg)": 58096.96,
"": "",
"High (troy oz)": 1809.18,
"Low (troy oz)": 1807.02,
"Close (troy oz)": 1807.02,
"__1": ""
},