Regex help for custom JSON filetype filter

HI there

I need to write a custom JSON filetype filter (TRADOS 2021) and am struggling with getting any regex to work for the JSON Paths in Trados Studio.

A sample of the JSON paths that would need to be translated are

bronze[0].localisable.title
bronze[0].localisable.subTitle
bronze[0].localisable.listItems
bronze[1].localisable.title
bronze[1].localisable.subTitle
bronze[1].localisable.listItems
bronze[1].localisable.ctas[0].text
bronze[1].localisable.ctas[1].text
silver[0].localisable.title
gold[0].localisable.ctas[0].text

I can't get the correct regex identified for the words bronze/gold/silver or the digits inside the [].

Any pointers would be appreciated

TIA

Peter

emoji
Parents
  •  

    Perhaps it would help if you shared a snippet of the json file?  The expressions look ok at first glance assuming that the structure of your JSON data aligns with these paths. So we're missing info to be able to assist you.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  • Hi  

    Here's the sample (randomized) code:

    {
    "bronze": [{
    "localisable": {
    "title": "This is Title 1",
    "subTitle": "This is SubTitle 1",
    "listItems": [
    "List Item 1"
    ],
    "ctas": [{
    "text": "Text 1"
    },
    {
    "text": "Text 2"
    }
    ]
    },
    "image": "URL1",
    "ctas": [{
    "link": "URL2"
    },
    {
    "link": "URL3"
    }
    ],
    "dates": {
    "start": "26/06/2023",
    "end": ""
    },
    "priority": "2",
    "publications": [
    "AB",
    "CD",
    "EFTG",
    "csdtggtf"
    ]
    },
    {
    "localisable": {
    "title": "This is Title 12",
    "subTitle": "This is SubTitle 14",
    "listItems": [
    "Item 2",
    "Item 23",
    "Item 33"
    ],
    "ctas": [{
    "text": "Text 1"
    },
    {
    "text": "Text 12"
    }
    ]
    },
    "image": "URL",
    "ctas": [{
    "lURL"
    },
    {
    "link": "IRL"
    }
    ],
    "dates": {
    "start": "28/06/2023",
    "end": "13/07/2023"
    },
    "priority": "3",
    "publications": [
    "AB",
    "CsdtggF",
    "sdtgg",
    "dsdsd"
    ]
    }
    ],
    "silver": [{
    "localisable": {
    "title": "Titlke 1",
    "subTitle": "Titkle 2",
    "listItems": [
    "Item 1",
    "Item 33 ",
    "Item 4"
    ],
    "ctas": [{
    "text": "Text 1"
    },
    {
    "text": "Text 12"
    }
    ]
    },
    "image": "URL",
    "ctas": [{
    "link": "URL"
    },
    {
    "link": "URL"
    }
    ],
    "dates": {
    "start": "28/06/2023",
    "end": "13/07/2023"
    },
    "priority": "3",
    "publications": [
    "AB",
    "CsdtggF",
    "sdtgg",
    "dsdsd"
    ]
    }],
    "gold": [{
    "localisable": {
    "title": "This is Title 1",
    "subTitle": "Totl 2",
    "listItems": [
    "Item 1",
    "Item 2",
    "Item 3"
    ],
    "ctas": [{
    "text": "Text 1"
    },
    {
    "text": "Text 12"
    }
    ]
    },
    "image": "URL",
    "ctas": [{
    "link": "URL"
    },
    {
    "link": "URL"
    }
    ],
    "dates": {
    "start": "28/06/2023",
    "end": "13/07/2023"
    },
    "priority": "3",
    "publications": [
    "AB",
    "CsdtggF",
    "sdtgg",
    "dsdsd"
    ]
    }]
    }

    TIIA

    Peter

    emoji
  • Thanks  

    The file you gave me contained an error in the "ctas" array under the second "bronze" object as one of the objects was missing a key for its value (which is "URL").  I had to fix that first as I couldn't parse your example at all.

    Here's my corrected file:

    {
      "bronze": [
        {
          "localisable": {
            "title": "This is Title 1",
            "subTitle": "This is SubTitle 1",
            "listItems": ["List Item 1"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 2"
              }
            ]
          },
          "image": "URL1",
          "ctas": [
            {
              "link": "URL2"
            },
            {
              "link": "URL3"
            }
          ],
          "dates": {
            "start": "26/06/2023",
            "end": ""
          },
          "priority": "2",
          "publications": ["AB", "CD", "EFTG", "csdtggtf"]
        },
        {
          "localisable": {
            "title": "This is Title 12",
            "subTitle": "This is SubTitle 14",
            "listItems": ["Item 2", "Item 23", "Item 33"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 12"
              }
            ]
          },
          "image": "URL",
          "ctas": [
            {
              "link": "URL"
            },
            {
              "link": "IRL"
            }
          ],
          "dates": {
            "start": "28/06/2023",
            "end": "13/07/2023"
          },
          "priority": "3",
          "publications": ["AB", "CsdtggF", "sdtgg", "dsdsd"]
        }
      ],
      "silver": [
        {
          "localisable": {
            "title": "Titlke 1",
            "subTitle": "Titkle 2",
            "listItems": ["Item 1", "Item 33 ", "Item 4"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 12"
              }
            ]
          },
          "image": "URL",
          "ctas": [
            {
              "link": "URL"
            },
            {
              "link": "URL"
            }
          ],
          "dates": {
            "start": "28/06/2023",
            "end": "13/07/2023"
          },
          "priority": "3",
          "publications": ["AB", "CsdtggF", "sdtgg", "dsdsd"]
        }
      ],
      "gold": [
        {
          "localisable": {
            "title": "This is Title 1",
            "subTitle": "Totl 2",
            "listItems": ["Item 1", "Item 2", "Item 3"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 12"
              }
            ]
          },
          "image": "URL",
          "ctas": [
            {
              "link": "URL"
            },
            {
              "link": "URL"
            }
          ],
          "dates": {
            "start": "28/06/2023",
            "end": "13/07/2023"
          },
          "priority": "3",
          "publications": ["AB", "CsdtggF", "sdtgg", "dsdsd"]
        }
      ]
    }

    Then I added all your rules and they seem to work just fine:

    Screenshot showing all the jsonpath rules added and the successful preview.

    Can you explain what your problem is exactly?

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
Reply
  • Thanks  

    The file you gave me contained an error in the "ctas" array under the second "bronze" object as one of the objects was missing a key for its value (which is "URL").  I had to fix that first as I couldn't parse your example at all.

    Here's my corrected file:

    {
      "bronze": [
        {
          "localisable": {
            "title": "This is Title 1",
            "subTitle": "This is SubTitle 1",
            "listItems": ["List Item 1"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 2"
              }
            ]
          },
          "image": "URL1",
          "ctas": [
            {
              "link": "URL2"
            },
            {
              "link": "URL3"
            }
          ],
          "dates": {
            "start": "26/06/2023",
            "end": ""
          },
          "priority": "2",
          "publications": ["AB", "CD", "EFTG", "csdtggtf"]
        },
        {
          "localisable": {
            "title": "This is Title 12",
            "subTitle": "This is SubTitle 14",
            "listItems": ["Item 2", "Item 23", "Item 33"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 12"
              }
            ]
          },
          "image": "URL",
          "ctas": [
            {
              "link": "URL"
            },
            {
              "link": "IRL"
            }
          ],
          "dates": {
            "start": "28/06/2023",
            "end": "13/07/2023"
          },
          "priority": "3",
          "publications": ["AB", "CsdtggF", "sdtgg", "dsdsd"]
        }
      ],
      "silver": [
        {
          "localisable": {
            "title": "Titlke 1",
            "subTitle": "Titkle 2",
            "listItems": ["Item 1", "Item 33 ", "Item 4"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 12"
              }
            ]
          },
          "image": "URL",
          "ctas": [
            {
              "link": "URL"
            },
            {
              "link": "URL"
            }
          ],
          "dates": {
            "start": "28/06/2023",
            "end": "13/07/2023"
          },
          "priority": "3",
          "publications": ["AB", "CsdtggF", "sdtgg", "dsdsd"]
        }
      ],
      "gold": [
        {
          "localisable": {
            "title": "This is Title 1",
            "subTitle": "Totl 2",
            "listItems": ["Item 1", "Item 2", "Item 3"],
            "ctas": [
              {
                "text": "Text 1"
              },
              {
                "text": "Text 12"
              }
            ]
          },
          "image": "URL",
          "ctas": [
            {
              "link": "URL"
            },
            {
              "link": "URL"
            }
          ],
          "dates": {
            "start": "28/06/2023",
            "end": "13/07/2023"
          },
          "priority": "3",
          "publications": ["AB", "CsdtggF", "sdtgg", "dsdsd"]
        }
      ]
    }

    Then I added all your rules and they seem to work just fine:

    Screenshot showing all the jsonpath rules added and the successful preview.

    Can you explain what your problem is exactly?

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
Children