Parsing JSON to see specific Key & Value

Hi,

I am setting up a project with JSON files to be translated.

I am trying to parse it to enhance workflow.
The structure of the JSON files are as follows:

Screenshot of JSON file in Trados Studio with text highlighted in green indicating translatable content and orange highlighting for 'slug' field.

With "$..content.*" I get everything that is highlighted in green (which is what needs to be translated). The file looks like this in Trados:

Trados Studio interface showing a list of strings with checkboxes, and a question mark indicating confusion about which string is the 'slug'.

I have been asked to translate the values of "name", "seotitle", "seodescription" and "content". The "slug" (highlighted in orange) is only to be translated if there is a color in it. For example, "thisisastring" should be left as is, but if it is "thisisastring-black", "black" should be translated.

The problem is, often name, seotitle, seodescription and slug are exactly identical. This means that it will be very easy to translate the value of "slug" by mistake, thinking it's one of the value of one of the other keys. The files are also different. Some files don't have slugs, some don't have seo descriptions. So I can't predict that it's always the fourth segment or something similar.

Is there a way for me to use both "$..content.*" and another expression to show me when the segment is actually a "slug"? Optimally the slug segment would say "slug": "thisisastring" (or something similar) so I always know which ones they are.


Thank you kindly for helping!
Have a nice day.



Generated Image Alt-Text
[edited by: Trados AI at 1:58 AM (GMT 0) on 29 Feb 2024]
emoji
  • If you are using Studio 2019, load the Supertext json file type from the appstore and import the rules in there. Then decide, which you need. This is the easiest way to deal with your problem.

    _________________________________________________________

    When asking for help here, please be as accurate as possible. Please always remember to give the exact version of product used and all possible error messages received. The better you describe your problem, the better help you will get.

    Want to learn more about Trados Studio? Visit the Community Hub. Have a good idea to make Trados Studio better? Publish it here.

  • Jerzy, thank you.

    I am using Studio 2021. I am using the Trados native JSON parser and I have never tried an app for this. I will download the app and see.

    I'm not sure, however, that I understand what you mean by "import the rules in there". How would I go about this? "$..content.*" is not an expression that I created, so I am not exactly fluent in the language "Parse". Do you have an idea of how these rules would look?

  • Trados Studio options window showing JSON file parsing settings with path filter rules. Highlighted instructions to remove unwanted rules and extract rules.

    Unfortunately, the native json file type does not support this feature.

    If you still have S2019, install the file type File Type Definition for JSON - Language Solutions | SDL there, then use "Extract" to extract the rules from your file(s), remove unwanted ones and prepare the project there. You can afterwards translate in S2021, but will need to create target in S2019.

    The process is very easy and self-explaining.

    _________________________________________________________

    When asking for help here, please be as accurate as possible. Please always remember to give the exact version of product used and all possible error messages received. The better you describe your problem, the better help you will get.

    Want to learn more about Trados Studio? Visit the Community Hub. Have a good idea to make Trados Studio better? Publish it here.

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 1:59 AM (GMT 0) on 29 Feb 2024]
  • I never had S2019 as I bought the program recently.
    Does this mean I won't be able to do this?

  • Autsch, unfortunately for the time being not. The Supertext file type is not (yet) available for S2021. In that very case you will be forced to writhe the paths on your own, unless someone here in the forum is able to give you the paths (I am not). Other solution would be having someone with Studio 2019 preparing the files for you. This is something I could imagine to be able to do. So if you wish, write an e-mail to info at tts-td dot com and give me exact information which elements need translation. I would then prepare a dummy package (with an empty TM—to be replaced by proper TM at your end) for you.

    _________________________________________________________

    When asking for help here, please be as accurate as possible. Please always remember to give the exact version of product used and all possible error messages received. The better you describe your problem, the better help you will get.

    Want to learn more about Trados Studio? Visit the Community Hub. Have a good idea to make Trados Studio better? Publish it here.

  • Hi 

    Actually, you can achieve this starting with Studio 2021 SR1 CU3. So be sure you are upgraded at least to CU3.

     As a new feature of CU3, Translatable checkbox was added in the Add JSON Path dialog.

    Trados Studio Add JSON Path dialog with fields for JSON Path, Document Structure Information set to Paragraph, Name of sibling defining SID, and a checked Translatable checkbox.

    Below, you can see each JSONPath with Translatable attribute set, and it works.

    Trados Studio Specified JSON paths for extracting table showing paths for slug and url with Document Structure Information set to Paragraph, SID Sibling blank, and Translatable set to False, and a path with a wildcard with Translatable set to True.

    Adding to my original post here, also you can make sure DSI is set something specific to slug so that you can filter for slug entries in Editor or add color to DSI column so it's easily recognizable without filtering. DSI viewer from AppStore is also great.

    I hope this helps.

    Thanks,

    Naoko

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 1:59 AM (GMT 0) on 29 Feb 2024]
  • Thank you so much, Naoko!

    I tried to create one path "$..content.*" and one "$..slug". I set the DSI of the slug to Label, and I can now successfully see all slugs as "LBL" in the editor! Absolutely amazing! Thank you!

    I would like to set a specific color to the DSI "LBL". If possible, how would I go about this? I looked under Options -> Colors but cannot find anything there.

    A side-question: To me, it doesn't exactly make sense that "$..slug" would match anything indented one level under "content". If "content" is found with "$..content", wouldn't then the reasonable path for the slug be "$...slug" (3 dots instead of 2) since it's one "level" below content?

  • Jerzy, I got a good answer from Naoko which allows me to solve this issue directly in S2021. Again, thank you for your great help!

  • Hi

    Sorry about the color for the DSI, In terms of JSON parser, you are stuck with what they have and colors are not customizable. The colors of DSI columns are customizable in other parsers such as XML. I have yellow/custard color for LBL. 

    In terms of .. (two dots), this is equivalent to // in XPath. You can find a mapping between XPath and JSONPath here. It is helpful when you know one of those to understand the other.

    goessner.net/.../

    Trados Studio Advanced Display Filter 2.0 interface showing filter options for Title, Paragraph, and Label with a yellowcustard color for LBL. No visible errors or warnings.

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 1:59 AM (GMT 0) on 29 Feb 2024]
  • Thank you for explaining and for that link. So with the information from that link in mind, I wonder if the better option to reach the slug is "$..content.slug" or "$..slug". Would you recommend any over the other or would I get the same result?

1 2