In [2]:
import json
import numpy as np
from pprint import pprint

with open('json_data/boxcartournament.json') as data_file:    
    data = json.load(data_file)

# pprint(data)

player2num = {}
num2player = []
which_player = 0
for match in data:
    get_match = match['match']
    pid1 = get_match['player1_id']
    pid2 = get_match['player2_id']
    if pid1 not in player2num.keys():
        player2num[pid1] = which_player
        num2player.append(pid1)
        which_player = which_player+1
    if pid2 not in player2num.keys():
        player2num[pid2] = which_player
        num2player.append(pid2)
        which_player = which_player+1  
    #print( pid1, pid2, get_match['winner_id'], get_match['loser_id'] )

numplayers = len(player2num)
gamemat = np.zeros( (numplayers,numplayers) )
matchmat = np.zeros( (numplayers,numplayers) )
for match in data:
    pid1 = match['match']['player1_id']
    pid2 = match['match']['player2_id']
    winid = match['match']['winner_id']
    loserid = match['match']['loser_id']
    p1wins = match['match']['scores_csv'][0]
    p2wins = match['match']['scores_csv'][2]
    matchmat[ player2num[winid], player2num[loserid] ] = matchmat[ player2num[winid], player2num[loserid] ] + 1
    gamemat[ player2num[pid1], player2num[pid2] ] = gamemat[ player2num[pid1], player2num[pid2] ] + int(p1wins)
    gamemat[ player2num[pid2], player2num[pid1] ] = gamemat[ player2num[pid2], player2num[pid1] ] + int(p2wins)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-6058d51aa432> in <module>()
      3 which_player = 0
      4 for match in data:
----> 5     get_match = match['match']
      6     pid1 = get_match['player1_id']
      7     pid2 = get_match['player2_id']

TypeError: string indices must be integers