import json id_names = { "data": { "floras": { "30": "multi flora jammu", "29": "kikar", "28": "sounf", "27": "sarbooja", "26": "karanja", "25": "neem", "24": "cotton", "23": "bantulsi", "22": "ajwain", "21": "aarhar", "20": "jammun", "19": "red honey/ moong", "18": "kashmiri kikar", "17": "banpyazi", "16": "beri", "14": "kala jeera", "13": "till", "15": "rubber", "12": "sunflower", "11": "coriander", "10": "barseem", "9": "khair", "7": "sesame", "31": "NA", "5": "eucalyptus", "8": "sunderban", "6": "multi flora", "4": "toriya/vegetables", "3": "litchi", "2": "forest honey", "1": "mustard" } } } def count_flora_ids(json_file): with open(json_file, 'r') as f: data = json.load(f) flora_counts = {} user_apiaries = data['data']['user_apiaries'] for apiary in user_apiaries: flora_id = apiary['flora_id'] if flora_id in flora_counts: flora_counts[flora_id] += 1 else: flora_counts[flora_id] = 1 return flora_counts if __name__ == "__main__": json_file = "Downloads/apiaries - UP.json" # Update with your JSON file path counts = count_flora_ids(json_file) print("Count of flora_ids:") for flora_id, count in counts.items(): print((id_names["data"]["floras"][str(flora_id)] + ": "+ str(count)))