Python JSON Parse サンプル

import json

f = open('json_file.json', 'r')
json_dict = json.load(f)
print('json_dict:{}'.format(type(json_dict)))


counter = {}

for idx1 in range(len(json_dict)):

    session = []

    speaker = json_dict[idx1]["speakers"]
    title = json_dict[idx1]["title"]

    print(title)

    for idx2 in range(len(speaker)):
        company = speaker[idx2]["company"]
        name = speaker[idx2]["name"]

        print("{}, {}".format(company, name))
        
        #if company not in session:
        #    session.append(company)

        if company not in counter.keys():
            counter[company] = 0

        counter[company] += 1

    print("------")

counter = sorted(counter.items(), reverse=True, key=lambda x:x[1])

for index in range(len(counter)):
    v = counter[index]
    print("{}, {}".format(v[0].replace(",", ""), v[1]))

コメントを残す

メールアドレスが公開されることはありません。