In google spreadsheet cell i have this text:
{"age_max":65,"age_min":18,"flexible_spec":[{"interests":[{"id":"6002867432822","name":"Beauty"},{"id":"6002991733794","name":"Beauty & Care"},{"id":"6003177110133","name":"Natural Beauty"},{"id":"6003211042524","name":"Health and Beauty Care"},{"id":"6003393295343","name":"Health And Beauty"},{"id":"6003460329503","name":"Beautiful Skin"},{"id":"6004111438209","name":"Facial care"}]}],"genders":[2],"geo_locations":{"countries":["SK"],"location_types":["home","recent"]},"locales":[2,33],"targeting_optimization":"none","publisher_platforms":["facebook"],"facebook_positions":["feed","right_hand_column","instant_article"],"device_platforms":["mobile","desktop"]};
Its JSON from Facebook API getting from Supermetrics.
Now i want to parse this cell, but this code doesnt work :-/
I am using this function in spreadsheet "=parseTargeting(A1)"
and this custom function in Script editor.
function parseTargeting(jsonData) {
var flexible_spec = jsonData["flexible_spec"];
var maxAge = jsonData["age_max"];
var minAge = jsonData["age_min"];
var interestsBasics = jsonData["flexible_spec"][0]["interests"][0]["name"];
var interestsBasicsCelkem = jsonData["flexible_spec"][0]["interests"].length-1;
var interests = "";
var output = [];
for(var i = 0; i<=interestsBasicsCelkem; i++){
interests += jsonData["flexible_spec"][0]["interests"][i]["name"]+ "\n";
}
var returnVek = "Vek:"+minAge + " - " + maxAge+" \n";
var returnInterests = "Zájmy:"+interests;
var returnString = returnVek + returnInterests;
return returnString;
}
This function return always Undefined. If i add this code
" var jsonData = {"age_max":65,"age_min":18,"flexible_spec":[{"interests":[{"id":"6002867432822","name":"Beauty"},{"id":"6002991733794","name":"Beauty & Care"},{"id":"6003177110133","name":"Natural Beauty"},{"id":"6003211042524","name":"Health and Beauty Care"},{"id":"6003393295343","name":"Health And Beauty"},{"id":"6003460329503","name":"Beautiful Skin"},{"id":"6004111438209","name":"Facial care"}]}],"genders":[2],"geo_locations":{"countries":["SK"],"location_types":["home","recent"]},"locales":[2,33],"targeting_optimization":"none","publisher_platforms":["facebook"],"facebook_positions":["feed","right_hand_column","instant_article"],"device_platforms":["mobile","desktop"]};
"
to function - then its work. But i need this function to get value from google spreadsheet cell dynamically.
I dont get it :-/ Can you help how to parse JSON from Google Spreadsheet Cell?