I don't know any Javascript. I have a .json file that looks like this:
{ "results": [
{
"challenger": {
"__type": "Pointer",
"className": "Player",
"objectId": "STWAxAHKay"
},
"challengerScore": 18,
"createdAt": "2014-12-05T21:43:01.099Z",
"defender": {
"__type": "Pointer",
"className": "Player",
"objectId": "UGAmRVd7Tr"
},
"defenderScore": 21,
"objectId": "pmiACGwe45",
"updatedAt": "2014-12-05T21:43:01.099Z"
},
{
"challenger": {
"__type": "Pointer",
"className": "Player",
"objectId": "STWAxAHKay"
},
"challengerScore": 23,
"createdAt": "2014-12-05T21:43:01.969Z",
"defender": {
"__type": "Pointer",
"className": "Player",
"objectId": "UGAmRVd7Tr"
},
"defenderScore": 25,
"objectId": "HqptXdYmQL",
"updatedAt": "2014-12-05T21:43:01.969Z"
}
]}
I'm reading it into my script like this:
var fs = require('fs');
var results = JSON.parse(fs.readFileSync('Game.json', 'utf8'));
results is an object but it's not an array.
I would like to make it an array so I can iterate through each game, grab the data I need from each game and use it to create a new object that I ultimately save in a .json file.
I would love for someone to guide me through this entire process but I would be thrilled if someone can just show me how to make an array of games that I can iterate through just to get me started.
Thank you.
results.results