XPath in JSON file

Hi Community,

We have received a sample JSON file to test if Trados Studio can handle it well.

I tried adding it to Studio and customise the parser settings, but actually with a first look in the file I'm not sure if it's not missing something, but I'm not too experienced in it, so I would like if you could confirm it, if the file in itself is complete.

Here is the file:

https://gist.github.com/litzinger/44cecca3406ef4669d0dc5e2ef9c3fe5 

It starts like this, does not seem to have a clear root element:

{
  "send_approval": "n",
  "publisher_save_status": "open",
  "publisher_view_status": "open",
  "site_language": "1",
  "submit": "save_and_close",
  "title": "Jamf Pro",
  "field_id_630": {
    "blocks_block_id_459538": {
      "draft": "0",
      "id": "459538",
      "blockDefinitionId": "10",
      "order": "1",
      "deleted": "false",
      "values": {
        "col_id_64": "comet",
        "col_id_70": [
          "8681",

}, "blocks_block_id_459546": { "draft": "0", "id": "459546", "blockDefinitionId": "7", "order": "9", "deleted": "false", "values": { "col_id_20": "Our Apple EMM makes sure everyone gets more out of their Apple devices with you to thank.", "col_id_121": "", "col_id_122": "center", "col_id_155": "center"


Under "values" they have "col_id_XX" elements which have the translatable content, but not always.

The instructions we received say that

Generally if the value is all lower cased and 1 word, or lower case and multiple words separated by an _ or - then it’s a variable, and not actual content. Thats probably a safer bet to do a regular expression match. This would match any value in a json object that starts with a lowercase letter, contain numbers, dashes, or underscores making it 1 word, or the words Yes and No (we use those values for true/false). ^([a-z0-9\-_|Yes|No])+$ (edited) 

If key matches (_\d+|title|text|content)$ AND value does _not_ match ^([a-z0-9\-_|Yes|No])+$  then it’s probably a safe bet that it is translatable text.

The "tree_order" parameter should always be excluded for translation.

Non translatable content also appears between curly brackets in some cases : exclude this as well

The only dates that should be translated are anything in the other fields you noted with underscores.



So this is one thing, but I'm not really sure where to start the parsing. Also if the file is complete because it seems to be lacking a root element, it looks like an excerpt but the customer says it should work.


What do you think?

Thank you!
Greta

Parents Reply
  • Unfortunately there isn't a way to use a pattern to take for example "col_id_"anynumber"".  I don't believe this is supported anywhere for jsonpath, not only Studio.  So you'll have to create rules for each key you want translated.  Like this..

    Trados Studio options window showing a list of JSON paths for extracting text, with keys like col_id_1, col_id_2, and col_id_3 labeled as Paragraph under Document Structure Information.

    I ran a regex on the json file itself in a text editor to find the appropriate keys based on this:

    Generally if the value is all lower cased and 1 word, or lower case and multiple words separated by an _ or - then it’s a variable, and not actual content. Thats probably a safer bet to do a regular expression match. This would match any value in a json object that starts with a lowercase letter, contain numbers, dashes, or underscores making it 1 word, or the words Yes and No (we use those values for true/false). ^([a-z0-9\-_|Yes|No])+$ (edited) 

    That's the idea anyway.  You should check it! I also used the html embedded content processor as this finishes the file off nicely.

    I put my settings file here to give you a head start:

    gm_json.zip

    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


    Generated Image Alt-Text
    [edited by: Trados AI at 4:37 AM (GMT 0) on 5 Mar 2024]
Children