I\'m new to JSON and I\'m working on extracting values from JSON data using Python. I\'m getting the JSON data using another shell script with cURL.
Here is my JSON
Please save the code into test.py
and data into test.json
.
test.py
import json
with open('/tmp/test.json') as f:
for i in f:
data = json.loads(i)
print("{Country} {count}".format(**data["result"]))
test.json
$ python test.py
AU 417
BG 7
CA 198
CH 1
CN 3
CR 1
DE 148
DK 1
FI 1
FR 1052
GB 1430
HK 243
VG 54
You can also try it in your prog:
for i in answer:
data = json.loads(i)
print("{Country} {count}".format(**data["result"]))