How To Extract Specific Multiple Values In Json Using Python?
I Have to extract specific multiple values and print those specific values in a file if possible. I tried the below code to do this JSON value from URL is: {'data': [{'value': '0.
Solution 1:
What you want is a loop
json_data = {'data': [{'value': '0.0.0.0'}, {'value': '0.0.0.1'}, {'value': '0.0.0.2'}]}
for x in json_data['data']:
print (x['value'])
Solution 2:
To write the values to a file, expand @ergonaut's answer as here:
json_data = {'data': [{'value': '0.0.0.0'}, {'value': '0.0.0.1'}, {'value': '0.0.0.2'}]}
withopen("test.txt", "w") as f:
for x in json_data['data']:
f.write(x['value'] + '\n')
Test the entries in test.txt
:
with open("test.txt", "r") as f:
data = f.readlines()
for line indata:
print line.rstrip('\n')
Output:
0.0.0.0
0.0.0.1
0.0.0.2
Post a Comment for "How To Extract Specific Multiple Values In Json Using Python?"