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

New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

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:

 

Bildschirmfoto 2022-05-16 um 08.58.50.png

 

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.

TOPICS
Error or problem , Expressions , Scripting

Views

95

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

New Here , May 16, 2022 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 🙂

Likes

Translate

Translate
Adobe Community Professional , May 16, 2022 May 16, 2022

I think this works:

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

Likes

Translate

Translate
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

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": ""
},

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

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.

Motion Graphics Brand Guidelines & Motion Graphics Responsive Design Toolkits

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Thanks, I was afraid so.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

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 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

I think this works:

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

LATEST

Like a clockwork, Dan saves the day 🙂 Thanks a lot! What's interesting is, that sourceData.lengt works when referenced to the footage itself (in the project panel) as Dan wrote, but not if referenced to the same json file as a layer - that's what I've tried before.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines