In google sheet, I’ve got a script to retrieve JSon from an url
function getTeamData() {
var DATA_SPREADSHEET_ID = "xxxx";
var ss = SpreadsheetApp.openById(DATA_SPREADSHEET_ID);
var TeamDataSheet = ss.getSheetByName("rawTeam");
TeamDataSheet.clearContents();
var url = 'xxxx';
var response = UrlFetchApp.fetch(url);
var content = response.getContentText();
var data = JSON.parse(content);
//Logger.log(JSON.stringify(data));
The problem I’ve got is that the JSon content look like this
{
"03wi4": {
"statsIncId": 5546,
"rotowireId": 3795,
"name": "Saunders, Wesley",
"fantraxId": "03wi4",
"team": "NY",
"position": "SG"
},
"059gh": {
"statsIncId": 6321,
"rotowireId": 4919,
"name": "Booth, Phil",
"fantraxId": "059gh",
"team": "(N/A)",
"position": "PG"
},
"02nfe": {
"statsIncId": 5020,
"rotowireId": 3308,
"sportRadarId": "c555e067-c4d5-43f6-99af-716b6005cbba",
"name": "Henson, John",
"fantraxId": "02nfe",
"team": "NY",
"position": "PF"
},
"033b7": {
"statsIncId": 5235,
"rotowireId": 3538,
"name": "Raduljica, Miroslav",
"fantraxId": "033b7",
"team": "(N/A)",
"position": "C"
},
...
}
I would like to be able to return the team for each of the entries but I don’t have a common first tag name…
Could you please help, the result should look like this :
059gh (N/A)
02nfe NY
033b7 (N/A)```
2
Answers
I believe your goal is as follows.
[["03wi4","NY"],["059gh","(N/A)"],["02nfe","NY"],["033b7","(N/A)"]]
from your showing JSON object.data
ofvar data = JSON.parse(content);
.In this case, how about the following modification?
Modified script:
When your previous question is considered, please modify the above script as follows.
From
To
Or,
From
To
Note:
data
is your showing JSON object. Please be careful about this.References:
Use Object.keys to iterate and Array.map :