jsonparsing.js
15.8 KB
let sampleJson = '{"get":"players","parameters":{"id":"276","season":"2019"},"errors":[],"results":1,"paging":{"current":1,"total":1},"response":[{"player":{"id":276,"name":"Neymar da Silva Santos J\u00fanior","firstname":"Neymar","lastname":"da Silva Santos J\u00fanior","age":30,"birth":{"date":"1992-02-05","place":"Mogi das Cruzes","country":"Brazil"},"nationality":"Brazil","height":"175 cm","weight":"68 kg","injured":false,"photo":"https:\/\/media.api-sports.io\/football\/players\/276.png"},"statistics":[{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":61,"name":"Ligue 1","country":"France","logo":"https:\/\/media.api-sports.io\/football\/leagues\/61.png","flag":"https:\/\/media.api-sports.io\/flags\/fr.svg","season":2019},"games":{"appearences":15,"lineups":15,"minutes":1322,"number":null,"position":"Attacker","rating":"8.053333","captain":false},"substitutes":{"in":0,"out":3,"bench":0},"shots":{"total":70,"on":36},"goals":{"total":13,"conceded":null,"assists":6,"saves":null},"passes":{"total":704,"key":39,"accuracy":79},"tackles":{"total":13,"blocks":0,"interceptions":4},"duels":{"total":null,"won":null},"dribbles":{"attempts":143,"success":88,"past":null},"fouls":{"drawn":62,"committed":14},"cards":{"yellow":3,"yellowred":1,"red":0},"penalty":{"won":1,"commited":null,"scored":4,"missed":1,"saved":null}},{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":65,"name":"Coupe de la Ligue","country":"France","logo":"https:\/\/media.api-sports.io\/football\/leagues\/65.png","flag":"https:\/\/media.api-sports.io\/flags\/fr.svg","season":2019},"games":{"appearences":3,"lineups":3,"minutes":300,"number":null,"position":"Attacker","rating":"7.533333","captain":false},"substitutes":{"in":0,"out":0,"bench":0},"shots":{"total":11,"on":5},"goals":{"total":1,"conceded":null,"assists":1,"saves":null},"passes":{"total":144,"key":8,"accuracy":75},"tackles":{"total":3,"blocks":1,"interceptions":1},"duels":{"total":24,"won":15},"dribbles":{"attempts":30,"success":11,"past":null},"fouls":{"drawn":14,"committed":1},"cards":{"yellow":0,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":0,"missed":0,"saved":null}},{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":66,"name":"Coupe de France","country":"France","logo":"https:\/\/media.api-sports.io\/football\/leagues\/66.png","flag":"https:\/\/media.api-sports.io\/flags\/fr.svg","season":2019},"games":{"appearences":2,"lineups":2,"minutes":180,"number":null,"position":"Attacker","rating":"7.550000","captain":false},"substitutes":{"in":0,"out":0,"bench":1},"shots":{"total":6,"on":3},"goals":{"total":2,"conceded":null,"assists":null,"saves":null},"passes":{"total":85,"key":4,"accuracy":76},"tackles":{"total":null,"blocks":0,"interceptions":1},"duels":{"total":16,"won":6},"dribbles":{"attempts":16,"success":10,"past":null},"fouls":{"drawn":3,"committed":3},"cards":{"yellow":1,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":1,"missed":0,"saved":null}},{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":2,"name":"UEFA Champions League","country":"World","logo":"https:\/\/media.api-sports.io\/football\/leagues\/2.png","flag":null,"season":2019},"games":{"appearences":7,"lineups":6,"minutes":584,"number":null,"position":"Attacker","rating":"7.750000","captain":false},"substitutes":{"in":1,"out":0,"bench":1},"shots":{"total":22,"on":6},"goals":{"total":3,"conceded":null,"assists":4,"saves":null},"passes":{"total":213,"key":16,"accuracy":73},"tackles":{"total":7,"blocks":0,"interceptions":2},"duels":{"total":74,"won":46},"dribbles":{"attempts":57,"success":37,"past":null},"fouls":{"drawn":28,"committed":9},"cards":{"yellow":3,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":0,"missed":0,"saved":null}},{"team":{"id":6,"name":"Brazil","logo":"https:\/\/media.api-sports.io\/football\/teams\/6.png"},"league":{"id":10,"name":"Friendlies","country":"World","logo":"https:\/\/media.api-sports.io\/football\/leagues\/10.png","flag":null,"season":2019},"games":{"appearences":5,"lineups":4,"minutes":240,"number":null,"position":"Attacker","rating":null,"captain":false},"substitutes":{"in":1,"out":2,"bench":1},"shots":{"total":null,"on":null},"goals":{"total":1,"conceded":null,"assists":null,"saves":null},"passes":{"total":null,"key":null,"accuracy":null},"tackles":{"total":null,"blocks":null,"interceptions":null},"duels":{"total":null,"won":null},"dribbles":{"attempts":null,"success":null,"past":null},"fouls":{"drawn":null,"committed":null},"cards":{"yellow":0,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":null,"missed":null,"saved":null}}]}]}';
sampleJson = JSON.parse(sampleJson);
console.log(sampleJson);
let playerName = sampleJson.response[0].player.name.toString()
console.log(playerName);
console.log(typeof(playerName));
console.log(JSON.stringify(sampleJson.response[0].player.name));
console.log(typeof(JSON.stringify(playerName)));
stringJson = sampleJson.toString();
console.log(sampleJson.toString());
console.log(typeof(stringJson));
console.log("hello");
console.log("bye");
let standingJson = {"get":"standings","parameters":{"league":"39","season":"2021"},"errors":[],"results":1,"paging":{"current":1,"total":1},"response":[{"league":{"id":39,"name":"Premier League","country":"England","logo":"https:\/\/media.api-sports.io\/football\/leagues\/39.png","flag":"https:\/\/media.api-sports.io\/flags\/gb.svg","season":2021,"standings":[[{"rank":1,"team":{"id":50,"name":"Manchester City","logo":"https:\/\/media.api-sports.io\/football\/teams\/50.png"},"points":93,"goalsDiff":73,"group":"Premier League","form":"WDWWW","status":"same","description":"Promotion - Champions League (Group Stage)","all":{"played":38,"win":29,"draw":6,"lose":3,"goals":{"for":99,"against":26}},"home":{"played":19,"win":15,"draw":2,"lose":2,"goals":{"for":58,"against":15}},"away":{"played":19,"win":14,"draw":4,"lose":1,"goals":{"for":41,"against":11}},"update":"2022-05-22T00:00:00+00:00"},{"rank":2,"team":{"id":40,"name":"Liverpool","logo":"https:\/\/media.api-sports.io\/football\/teams\/40.png"},"points":92,"goalsDiff":68,"group":"Premier League","form":"WWWDW","status":"same","description":"Promotion - Champions League (Group Stage)","all":{"played":38,"win":28,"draw":8,"lose":2,"goals":{"for":94,"against":26}},"home":{"played":19,"win":15,"draw":4,"lose":0,"goals":{"for":49,"against":9}},"away":{"played":19,"win":13,"draw":4,"lose":2,"goals":{"for":45,"against":17}},"update":"2022-05-22T00:00:00+00:00"},{"rank":3,"team":{"id":49,"name":"Chelsea","logo":"https:\/\/media.api-sports.io\/football\/teams\/49.png"},"points":74,"goalsDiff":43,"group":"Premier League","form":"WDWDL","status":"same","description":"Promotion - Champions League (Group Stage)","all":{"played":38,"win":21,"draw":11,"lose":6,"goals":{"for":76,"against":33}},"home":{"played":19,"win":9,"draw":7,"lose":3,"goals":{"for":37,"against":22}},"away":{"played":19,"win":12,"draw":4,"lose":3,"goals":{"for":39,"against":11}},"update":"2022-05-22T00:00:00+00:00"},{"rank":4,"team":{"id":47,"name":"Tottenham","logo":"https:\/\/media.api-sports.io\/football\/teams\/47.png"},"points":71,"goalsDiff":29,"group":"Premier League","form":"WWWDW","status":"same","description":"Promotion - Champions League (Group Stage)","all":{"played":38,"win":22,"draw":5,"lose":11,"goals":{"for":69,"against":40}},"home":{"played":19,"win":13,"draw":1,"lose":5,"goals":{"for":38,"against":19}},"away":{"played":19,"win":9,"draw":4,"lose":6,"goals":{"for":31,"against":21}},"update":"2022-05-22T00:00:00+00:00"},{"rank":5,"team":{"id":42,"name":"Arsenal","logo":"https:\/\/media.api-sports.io\/football\/teams\/42.png"},"points":69,"goalsDiff":13,"group":"Premier League","form":"WLLWW","status":"same","description":"Promotion - Europa League (Group Stage)","all":{"played":38,"win":22,"draw":3,"lose":13,"goals":{"for":61,"against":48}},"home":{"played":19,"win":13,"draw":2,"lose":4,"goals":{"for":35,"against":17}},"away":{"played":19,"win":9,"draw":1,"lose":9,"goals":{"for":26,"against":31}},"update":"2022-05-22T00:00:00+00:00"},{"rank":6,"team":{"id":33,"name":"Manchester United","logo":"https:\/\/media.api-sports.io\/football\/teams\/33.png"},"points":58,"goalsDiff":0,"group":"Premier League","form":"LLWDL","status":"same","description":"Promotion - Europa League (Group Stage)","all":{"played":38,"win":16,"draw":10,"lose":12,"goals":{"for":57,"against":57}},"home":{"played":19,"win":10,"draw":5,"lose":4,"goals":{"for":32,"against":22}},"away":{"played":19,"win":6,"draw":5,"lose":8,"goals":{"for":25,"against":35}},"update":"2022-05-22T00:00:00+00:00"},{"rank":7,"team":{"id":48,"name":"West Ham","logo":"https:\/\/media.api-sports.io\/football\/teams\/48.png"},"points":56,"goalsDiff":9,"group":"Premier League","form":"LDWLL","status":"same","description":"Promotion - Europa Conference League (Qualification)","all":{"played":38,"win":16,"draw":8,"lose":14,"goals":{"for":60,"against":51}},"home":{"played":19,"win":9,"draw":5,"lose":5,"goals":{"for":33,"against":26}},"away":{"played":19,"win":7,"draw":3,"lose":9,"goals":{"for":27,"against":25}},"update":"2022-05-22T00:00:00+00:00"},{"rank":8,"team":{"id":46,"name":"Leicester","logo":"https:\/\/media.api-sports.io\/football\/teams\/46.png"},"points":52,"goalsDiff":3,"group":"Premier League","form":"WDWWL","status":"same","description":null,"all":{"played":38,"win":14,"draw":10,"lose":14,"goals":{"for":62,"against":59}},"home":{"played":19,"win":10,"draw":4,"lose":5,"goals":{"for":34,"against":23}},"away":{"played":19,"win":4,"draw":6,"lose":9,"goals":{"for":28,"against":36}},"update":"2022-05-22T00:00:00+00:00"},{"rank":9,"team":{"id":51,"name":"Brighton","logo":"https:\/\/media.api-sports.io\/football\/teams\/51.png"},"points":51,"goalsDiff":-2,"group":"Premier League","form":"WDWWD","status":"same","description":null,"all":{"played":38,"win":12,"draw":15,"lose":11,"goals":{"for":42,"against":44}},"home":{"played":19,"win":5,"draw":7,"lose":7,"goals":{"for":19,"against":23}},"away":{"played":19,"win":7,"draw":8,"lose":4,"goals":{"for":23,"against":21}},"update":"2022-05-22T00:00:00+00:00"},{"rank":10,"team":{"id":39,"name":"Wolves","logo":"https:\/\/media.api-sports.io\/football\/teams\/39.png"},"points":51,"goalsDiff":-5,"group":"Premier League","form":"LDLDL","status":"same","description":null,"all":{"played":38,"win":15,"draw":6,"lose":17,"goals":{"for":38,"against":43}},"home":{"played":19,"win":7,"draw":3,"lose":9,"goals":{"for":20,"against":25}},"away":{"played":19,"win":8,"draw":3,"lose":8,"goals":{"for":18,"against":18}},"update":"2022-05-22T00:00:00+00:00"},{"rank":11,"team":{"id":34,"name":"Newcastle","logo":"https:\/\/media.api-sports.io\/football\/teams\/34.png"},"points":49,"goalsDiff":-18,"group":"Premier League","form":"WWLLW","status":"same","description":null,"all":{"played":38,"win":13,"draw":10,"lose":15,"goals":{"for":44,"against":62}},"home":{"played":19,"win":8,"draw":6,"lose":5,"goals":{"for":26,"against":27}},"away":{"played":19,"win":5,"draw":4,"lose":10,"goals":{"for":18,"against":35}},"update":"2022-05-22T00:00:00+00:00"},{"rank":12,"team":{"id":52,"name":"Crystal Palace","logo":"https:\/\/media.api-sports.io\/football\/teams\/52.png"},"points":48,"goalsDiff":4,"group":"Premier League","form":"WLDWW","status":"same","description":null,"all":{"played":38,"win":11,"draw":15,"lose":12,"goals":{"for":50,"against":46}},"home":{"played":19,"win":7,"draw":8,"lose":4,"goals":{"for":27,"against":17}},"away":{"played":19,"win":4,"draw":7,"lose":8,"goals":{"for":23,"against":29}},"update":"2022-05-22T00:00:00+00:00"},{"rank":13,"team":{"id":55,"name":"Brentford","logo":"https:\/\/media.api-sports.io\/football\/teams\/55.png"},"points":46,"goalsDiff":-8,"group":"Premier League","form":"LWWLD","status":"same","description":null,"all":{"played":38,"win":13,"draw":7,"lose":18,"goals":{"for":48,"against":56}},"home":{"played":19,"win":7,"draw":3,"lose":9,"goals":{"for":22,"against":21}},"away":{"played":19,"win":6,"draw":4,"lose":9,"goals":{"for":26,"against":35}},"update":"2022-05-22T00:00:00+00:00"},{"rank":14,"team":{"id":66,"name":"Aston Villa","logo":"https:\/\/media.api-sports.io\/football\/teams\/66.png"},"points":45,"goalsDiff":-2,"group":"Premier League","form":"LDDLW","status":"same","description":null,"all":{"played":38,"win":13,"draw":6,"lose":19,"goals":{"for":52,"against":54}},"home":{"played":19,"win":6,"draw":5,"lose":8,"goals":{"for":29,"against":29}},"away":{"played":19,"win":7,"draw":1,"lose":11,"goals":{"for":23,"against":25}},"update":"2022-05-22T00:00:00+00:00"},{"rank":15,"team":{"id":41,"name":"Southampton","logo":"https:\/\/media.api-sports.io\/football\/teams\/41.png"},"points":40,"goalsDiff":-24,"group":"Premier League","form":"LLLLD","status":"same","description":null,"all":{"played":38,"win":9,"draw":13,"lose":16,"goals":{"for":43,"against":67}},"home":{"played":19,"win":6,"draw":7,"lose":6,"goals":{"for":23,"against":24}},"away":{"played":19,"win":3,"draw":6,"lose":10,"goals":{"for":20,"against":43}},"update":"2022-05-22T00:00:00+00:00"},{"rank":16,"team":{"id":45,"name":"Everton","logo":"https:\/\/media.api-sports.io\/football\/teams\/45.png"},"points":39,"goalsDiff":-23,"group":"Premier League","form":"LWLDW","status":"same","description":null,"all":{"played":38,"win":11,"draw":6,"lose":21,"goals":{"for":43,"against":66}},"home":{"played":19,"win":9,"draw":2,"lose":8,"goals":{"for":27,"against":25}},"away":{"played":19,"win":2,"draw":4,"lose":13,"goals":{"for":16,"against":41}},"update":"2022-05-22T00:00:00+00:00"},{"rank":17,"team":{"id":63,"name":"Leeds","logo":"https:\/\/media.api-sports.io\/football\/teams\/63.png"},"points":38,"goalsDiff":-37,"group":"Premier League","form":"WDLLL","status":"same","description":null,"all":{"played":38,"win":9,"draw":11,"lose":18,"goals":{"for":42,"against":79}},"home":{"played":19,"win":4,"draw":6,"lose":9,"goals":{"for":19,"against":38}},"away":{"played":19,"win":5,"draw":5,"lose":9,"goals":{"for":23,"against":41}},"update":"2022-05-22T00:00:00+00:00"},{"rank":18,"team":{"id":44,"name":"Burnley","logo":"https:\/\/media.api-sports.io\/football\/teams\/44.png"},"points":35,"goalsDiff":-19,"group":"Premier League","form":"LDLLW","status":"same","description":"Relegation - Championship","all":{"played":38,"win":7,"draw":14,"lose":17,"goals":{"for":34,"against":53}},"home":{"played":19,"win":5,"draw":6,"lose":8,"goals":{"for":18,"against":25}},"away":{"played":19,"win":2,"draw":8,"lose":9,"goals":{"for":16,"against":28}},"update":"2022-05-22T00:00:00+00:00"},{"rank":19,"team":{"id":38,"name":"Watford","logo":"https:\/\/media.api-sports.io\/football\/teams\/38.png"},"points":23,"goalsDiff":-43,"group":"Premier League","form":"LLDLL","status":"same","description":"Relegation - Championship","all":{"played":38,"win":6,"draw":5,"lose":27,"goals":{"for":34,"against":77}},"home":{"played":19,"win":2,"draw":2,"lose":15,"goals":{"for":17,"against":46}},"away":{"played":19,"win":4,"draw":3,"lose":12,"goals":{"for":17,"against":31}},"update":"2022-05-22T00:00:00+00:00"},{"rank":20,"team":{"id":71,"name":"Norwich","logo":"https:\/\/media.api-sports.io\/football\/teams\/71.png"},"points":22,"goalsDiff":-61,"group":"Premier League","form":"LDLLL","status":"same","description":"Relegation - Championship","all":{"played":38,"win":5,"draw":7,"lose":26,"goals":{"for":23,"against":84}},"home":{"played":19,"win":3,"draw":3,"lose":13,"goals":{"for":12,"against":43}},"away":{"played":19,"win":2,"draw":4,"lose":13,"goals":{"for":11,"against":41}},"update":"2022-05-22T00:00:00+00:00"}]]}}]};
console.log(standingJson);
console.log(standingJson);
console.log(standingJson.response[0]);
console.log(standingJson.response[0].league);
for(var i = 0; i < 20; i++){
console.log(standingJson.response[0].league.standings[0][i].rank + "|" + standingJson.response[0].league.standings[0][i].team.name);
}