nick34992
6/1/2016 - 4:12 PM

Parse JSON for Sum Total of Integer Values

Parse JSON for Sum Total of Integer Values

#!/usr/bin/python2.7

import json
import urllib

file_object = open('comments_276694.json')
raw_json = file_object.read()
json_dictionary = json.loads(raw_json)
total = 0
for json_item in json_dictionary['comments'] :
    q = json_item['count']
    w = int(q)
    total = total + w

print total
{
  "comments":[
    {
      "name":"Nirvana",
      "count":100
    },
    {
      "name":"Hana",
      "count":97
    },
    {
      "name":"Lilly",
      "count":97
    },
    {
      "name":"Noor",
      "count":97
    },
    {
      "name":"Kelsie",
      "count":96
    },
    {
      "name":"Jordy",
      "count":95
    },
    {
      "name":"Fiona",
      "count":95
    },
    {
      "name":"Rosie",
      "count":87
    },
    {
      "name":"Zuriel",
      "count":87
    },
    {
      "name":"Minaal",
      "count":86
    },
    {
      "name":"Janna",
      "count":83
    },
    {
      "name":"Milos",
      "count":80
    },
    {
      "name":"Inayah",
      "count":80
    },
    {
      "name":"Haylie",
      "count":78
    },
    {
      "name":"Areej",
      "count":77
    },
    {
      "name":"Millan",
      "count":76
    },
    {
      "name":"Airlie",
      "count":74
    },
    {
      "name":"Mirran",
      "count":71
    },
    {
      "name":"Chris",
      "count":70
    },
    {
      "name":"Moosa",
      "count":68
    },
    {
      "name":"Ashlin",
      "count":67
    },
    {
      "name":"Jingyi",
      "count":64
    },
    {
      "name":"Roray",
      "count":61
    },
    {
      "name":"Tee",
      "count":60
    },
    {
      "name":"Ruslan",
      "count":60
    },
    {
      "name":"Aliya",
      "count":60
    },
    {
      "name":"Fionnah",
      "count":58
    },
    {
      "name":"Elen",
      "count":51
    },
    {
      "name":"Virginie",
      "count":51
    },
    {
      "name":"Jayhan",
      "count":49
    },
    {
      "name":"Milley",
      "count":48
    },
    {
      "name":"Kaid",
      "count":33
    },
    {
      "name":"Polly",
      "count":27
    },
    {
      "name":"Avsta",
      "count":27
    },
    {
      "name":"Kieara",
      "count":24
    },
    {
      "name":"Areeb",
      "count":23
    },
    {
      "name":"Kemi",
      "count":22
    },
    {
      "name":"Keelin",
      "count":18
    },
    {
      "name":"Tamlah",
      "count":17
    },
    {
      "name":"Maros",
      "count":17
    },
    {
      "name":"Lexy",
      "count":16
    },
    {
      "name":"Jamal",
      "count":15
    },
    {
      "name":"Morag",
      "count":13
    },
    {
      "name":"Shahna",
      "count":10
    },
    {
      "name":"Codie",
      "count":8
    },
    {
      "name":"Marrwa",
      "count":7
    },
    {
      "name":"Tori",
      "count":6
    },
    {
      "name":"Riach",
      "count":5
    },
    {
      "name":"Aahana",
      "count":5
    },
    {
      "name":"Kyle",
      "count":1
    }
  ]
}