Reputation: 11
I must get a value in a json data like in following link: Value in json data (sorry because I can't emb image). I need to get value of "DT sau CK" and I see that it's value is an empty array [ ]. My function is:
function test () {
api_url = 'https://my url....'
var result = UrlFetchApp.fetch(api_url);
var data = JSON.parse(result);
var dtt = data['chart']['data'][2]['value'];
if (dtt == false || dtt.length == 0) {
dtt = 0;
} else {
dtt = data['chart']['data'][2]['value'];
}
return Number(dtt)
}
Upvotes: 0
Views: 4614
Reputation: 39
I faced same issue recently, the solution is to just delete empty/extra columns.
Upvotes: 0
Reputation: 1321
Maybe you can add this to replace empty arrays with '0':
chart.data.forEach(function (item) {
if (item.value.length===0) {
item.value=0;
}
});
Upvotes: 1