r/GoogleAppsScript • u/Its_Fabian_H • Nov 29 '20
Question JSON API / DeepL API In Google Scripts
Hi Guys,
I am not a coder, just someone who tries to learn Google Scripts for personal purposes. Apologies, if this is a very stupid question! I access the DeepL API in Google Scripts, which works just fine.
var url consists of my DeepL API code and the text it shall translate (e.g. "Hi, I am Fabian").
var response = UrlFetchApp.fetch(url); var json = response.getContentText(); var data = JSON.parse(json); Logger.log(data);
This returns the following:
{translations=[{detected_source_language=EN, text=Hallo, Ich bin Fabian.}]}
I want the output to be just the translated text ("Hallo, Ich bin Fabian."). I tried to get there by changing Logger.log(data) to Logger.log(data.translations.text), which then unfortunately returns "null". What am I doing wrong?
3
u/Its_Fabian_H Nov 29 '20
Thanks alot - jt works!!! :)