jsonparsing.js
5.23 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");