Legacy Dev Forum Posts

 View Only

Sign Up

Data action response templet

  • 1.  Data action response templet

    Posted 06-05-2025 18:42

    AnilKumarN | 2021-01-12 16:41:50 UTC | #1

    HI Team, we did the translate API and getting the json response, and the output is not mapped to the required variable, i did applied the translate mapping but its not working. below is the details and please help me to resolve the translation mapping for the response

    data action: { "requestUrlTemplate": "https://translation.googleapis.com/language/translate/v2?q=${input.q}&source=${input.source}&target=${input.target}&format=text&key="XXXXXXXXXXX", "requestType": "POST", "headers": { "Content-Type": "application/json; charset=UTF-8" }, "requestTemplate": "${input.rawRequest}" }

    output Contact is: { "type": "object", "properties": { "translatedText": { "type": "string" } }, "additionalProperties": true }

    and we are getting the json ouput as : { "data.translations.translatedText": [ "HI + cool", "Bonjour cool" ] }

    modified response templet which gives error: " Resolve translation map: Failed while processing the translation map. Could not resolve value for the key: 'translatedText' and no default value was configured. Additional details: Expected to find an object with property ['translatedText'] in path $['data']['translations'] but found 'java.util.ArrayList'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'."

    { "translationMap": { "translatedText": "$.data.translations.translatedText[1]" }, "translationMapDefaults": {}, "successTemplate": "{\n \"translatedText\": ${translatedText}\n}" }


    Jerome.Saint-Marc | 2021-01-12 17:11:18 UTC | #2

    Hello,

    Are you sure about the json output of this request? This google page describes a different format. It would be better if you could copy the full output - either as seen in the Data Action Test, or using curl.

    Isn't it something like this instead?

    {
      "data": {
        "translations": [
          {
            "translatedText": "HI + cool",
            "model": "..."
          },
          {
            "translatedText": "Bonjour cool",
            "model": "...."
          }
        ]
      }
    }

    In this case, in translationMap, you would use: "translatedText": "$.data.translations[1].translatedText"

    Regards,


    Jason_Mathison | 2021-01-12 17:14:38 UTC | #3

    Hi AnilKumarN,

    I highly recommend working through your JSONPath in http://jsonpath.herokuapp.com/ before sticking it into your translation map.

    It looks like the key you are looking for has dots in it, which is throwing things off. Switching your JSONPath to using this format should work: .["dots.make.things.hard"][1]

    --Jason


    AnilKumarN | 2021-01-13 11:03:41 UTC | #4

    Jerome.Saint-Marc, post:2, topic:9671
    { "data": { "translations": [ { "translatedText": "HI + cool", "model": "..." }, { "translatedText": "Bonjour cool", "model": "...." } ] } }

    Thanks Jason, it worked, thanks for the quick response


    system | 2021-02-13 11:13:34 UTC | #5

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 9671