• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Expressions - how to parse external JSON to get key-value string rather than number

Explorer ,
Apr 17, 2023 Apr 17, 2023

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:

{
  "text": "The same face: the very same. Marley wore his pigtail, usual waistcoat, tights and boots. ",
  "tokens": [
    {
      "id": 0,
      "start": 0,
      "end": 3,
      "tag": "DT",
      "pos": "DET",
      "morph": "Definite=Def|PronType=Art",
      "lemma": "the"
    },
    {
      "id": 1,
      "start": 4,
      "end": 8,
      "tag": "JJ",
      "pos": "ADJ",
      "morph": "Degree=Pos",
      "lemma": "same"
    },

 

TOPICS
Expressions , How to

Views

286

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
LEGEND ,
Apr 18, 2023 Apr 18, 2023

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

Votes

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
Explorer ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

LATEST

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 🙂  

Votes

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