KRL response processing

I am sending a google request through my API using KRL and this will be the literal response I get from them:

handleResponse({ "data": { "responses": [ { "response": "successful" } ] } } );

How did you recommend me to handle this through pick, since it is not a "valid" JSON syntax? It contains valid JSON syntax, but is generally invalid. Thank you for your help.

+3
source share
1 answer

Update. By looking at the Google translate API, it looks like the JSONP callback parameter is optional. Do not specify a callback and you will no longer have this problem. :)

http://code.google.com/apis/language/translate/v2/using_rest.html#WorkingResults

The best option:

, API Google, . JSON JSONP, pick.

:

API JSONP, , JSON, pick.

:

  • JSONP beesting encode

:

ruleset a60x494 {
  meta {
    name "jsonp-to-json-test"
    description <<
      jsonp-to-json-test
    >>
    author "Mike Grace"
    logging on
  }

  global {
    returnedJsonpAsString = 'handleResponse({ "data": { "responses": [ { "response": "successful" } ] } } );';
    datasource googleApi <- "blah blah blah";
  }

  rule fix_jsonp_to_json {
    select when pageview ".*"
    pre {
      cleanJson = returnedJsonpAsString.replace(re/^.*\((.*)\);/,"$1");
      response = cleanJson.decode().pick("$..response");
    }
    {
      notify("Response",response) with sticky = true;
      emit <|
        console.log(returnedJsonp);
        console.log(cleanJson);
      |>;
    }
  }
}
+5

Source: https://habr.com/ru/post/1780960/


All Articles