ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Refer to JSON data by index AND attribute name

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jon Smith
Refer to JSON data by index AND attribute name
on Aug 20, 2019 at 6:36:04 pm
Last Edited By Jon Smith on Aug 20, 2019 at 6:37:22 pm

Hey all, I'm trying to work with JSON data and referring to the data by both index and attribute name. I tried a couple different methods but I'm not able to get it to work. I'm guessing it's a syntax thing but I'm not sure. Any help is appreciated!


Example JSON:
{
"item1": {
"name": "Item 1 Name",
"parameter": "Item 1 parameter",
},
"item2": {
"name": "Item 2 Name",
"parameter": "Item 2 parameter",
},
"item3": {
"name": "Item 3 Name",
"parameter": "Item 3 parameter",
}
}

expression method #1
myData = eval(footage("sample.json").sourceData);
myData.item1.name; // works
myData[0].name; //doesn't work


expression method #2
footage("sample.json").dataValue([0, 0]); //works
footage("sample.json").dataValue([0, name]); //doesn't work


Return to posts index

Jon Smith
Re: Refer to JSON data by index AND attribute name
on Aug 21, 2019 at 6:34:57 pm

I figured it out. I had to relayout the JSON to look like this:

{
"item": [
{
"name": "Item 1 Name",
"parameter": "Item 1 parameter",
},
{
"name": "Item 2 Name",
"parameter": "Item 2 parameter",
},
{
"name": "Item 3 Name",
"parameter": "Item 3 parameter",
}
]
}

Then this works:
myData = eval(footage("sample.json").sourceData);
myData.item[0].name; // returns "Item 1 Name"



Return to posts index

Tomas Bumbulevičius
Re: Refer to JSON data by index AND attribute name
on Aug 22, 2019 at 4:56:31 am

Hey Jon, good to see you have found a workaround. Yet on the other hand, it is not required to do the following in order to access items.

Have a look here: https://stackoverflow.com/questions/7027051/access-json-or-js-property-usin...

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]