Skip to main content
Participant
September 16, 2024
Answered

Customize json file controlled text via drop-down menu

  • September 16, 2024
  • 1 reply
  • 324 views

Hello everyone and thank you so much for taking the time 🙂

 

I would like to use a drop-down menu to select the language in a json file (background: I have 12 videos with 15 different languages and I would like to save time and avoid errors).

 

Here is my exemplary json file (example.json):

{
	"text1" : {
		"english" : "I love my job",
		"deutsch" : "Ich liebe meinen job",
		"nederlands" : "Ik hou van mijn werk",
		"frans" : "J'aime mon travail"
	},
	"text2" : {
		"english" : "Why the hell can't that work?",
		"deutsch" : "Warum zur Hölle geht das nicht???",
		"nederlands" : "Waarom kun je dat verdomme niet doen?",
		"frans" : "Pourquoi ça ne marche pas ?"
	}
}

 

With these lines I access the json file as usual and get the text “I love my job”

myData = footage("example.json").sourceData;
myData.text1.english

 

In my idea I have to make the “english” somehow accessible in the expression.

   myData.text1.some-magic-linked-to-drop-down

 

I normally control drop-down menus using this expression here:

dropMenu = thisComp.layer("language").effect("dropdown")("menu").value;
language = ["english", "deutsch", "nederlands", "frans"];

language [dropMenu - 1]

 

Sometimes I get this somehow by myself (I can't program, but I'm good at googling ^^).
But in this case I can't get the two expressions linked so that I can access the json file with the drop-down menu.

 

Here is one of my miserable attempt:

 

dropMenu = thisComp.layer("language").effect("dropdown")("menu").value;
language = ["english", "deutsch", "nederlands", "frans"];
myData = footage("example.json").sourceData;
select = language [dropMenu - 1]

myData.text1.select

 

Which doesn't work at all...

 

In this sense: HELP

And thank you so much!!!

🙂

This topic has been closed for replies.
Correct answer Airweb_AE

Try this:

dropMenu = thisComp.layer("language").effect("dropdown")("menu").value;
language = ["english", "deutsch", "nederlands", "frans"];
myData = footage("example.json").sourceData;
select = language [dropMenu - 1];

// myData.text1.select
   myData.text1[select]

1 reply

Airweb_AECorrect answer
Legend
September 16, 2024

Try this:

dropMenu = thisComp.layer("language").effect("dropdown")("menu").value;
language = ["english", "deutsch", "nederlands", "frans"];
myData = footage("example.json").sourceData;
select = language [dropMenu - 1];

// myData.text1.select
   myData.text1[select]
Participant
September 16, 2024

Thank you sooooooo much!!!

That worked like a charm ❤️