How to count items in JSON data How to count items in JSON data python python

How to count items in JSON data


import jsonjson_data = json.dumps({  "result":[    {      "run":[        {          "action":"stop"        },        {          "action":"start"        },        {          "action":"start"        }      ],      "find": "true"    }  ]})item_dict = json.loads(json_data)print len(item_dict['result'][0]['run'])

Convert it in dict.


You're close. A really simple solution is just to get the length from the 'run' objects returned. No need to bother with 'load' or 'loads':

len(data['result'][0]['run'])