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.
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.
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.
Copy link to clipboard
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.
Thanks, I was afraid so.
All engines Stop! I've found a solution! extendScript to the rescue:
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
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.