Skip to content

Instantly share code, notes, and snippets.

@chapel
Created October 17, 2010 15:12
Show Gist options
  • Save chapel/630933 to your computer and use it in GitHub Desktop.
Save chapel/630933 to your computer and use it in GitHub Desktop.
{"players":
{
"gamertag": [ //gamertag would be set inside the loop through a variable, like "chapel" or "awesome"
{
"rating": 1234,
"standing": 1
}
],
"chapel": [
{
"rating": 2345,
"standing": 2
}
]
}
}
@chapel
Copy link
Author

chapel commented Oct 17, 2010

Here is the loop I am trying to make output the above json.

players.some(function(player) {
var gamertag = player.PlayerDetail.gamertag,
rating = player.Rating,
standing = player.IndividualStandingWithNoRegardForTeams;
data[gamertag] = {"rating": rating, "standing": standing};
count--;
if (count <= 0) {
callback(true);
gamesWrite.saveDoc(gameId, JSON.stringify(data), function(er, ok) {
if (er) throw new Error(JSON.stringify(er));
console.log('wrote '+gameId);
});
return true;
}
});

@shripadk
Copy link

Ok i don't really know anything about data so i will assume here:

        var gamertag = player.PlayerDetail.gamertag,
                rating = player.Rating,
                standing = player.IndividualStandingWithNoRegardForTeams;

    var data = {"players": {gamertag: []}}; // Assumed!

    data.players.gamertag.push({"rating": rating, "standing": standing})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment