Expressions - how to parse external JSON to get key-value string rather than number
Copy link to clipboard
Copied
Hello,
I'd like to create an expression to call an external json file (data2.json) which contains part-of-speech (pos) tags. They are expressed as key-value pairs, eg "pos": "VERB". I would like to get pos-tagged words (eg 'VERB') and assign them a different colour.
Am an Expressions newbie - sorry! Don't know if this is even possible. So far after lots of online videos 🙂 I can
- call the 'text' string - footage("data2.json").dataValue([0]);
- call a numerical token value - thisComp.layer("data2.json")("Data")("Outline")("tokens")("tokens 1")("end")
But can't work out how to call a string value from key-value pair.
Any help much appreciated!
The JSON has this structure:
Copy link to clipboard
Copied
You would probably sort them into an array based on their indexes and simply use that. Otherwise it may just be simpler to just export the files in a simpler structure. Parsing such complex node hierarchies for potentially hundreds or thousands of words is going to drag down performance massively.
Mylenium
Copy link to clipboard
Copied
Thanks so much for your help, Mylenium! It will only be up to 50 words, but I get your point that it's better to simplify the external file.
I just managed to get the value string by using this in a text layer: thisComp.layer("data2.json")("Data")("Outline")("tokens")("tokens 5")("lemma")
and this in the data2.json layer: footage("data2.json").dataValue([1,1,4])
which for a newbie was v exciting! But discovered that 'tokens 5' isn't a useful name for indexing 🙂

