Answers for "json.loads get value"

0

get value json python

print(json_object_string)
OUTPUT
{"id":"20", "name":"Bob"}

json_object = json.loads(json_object_string)

print(json_object["name"])
OUTPUT
Bob
Posted by: Guest on March-20-2021
2

python json file operations

import json # Imports the json file that we need
with open("jsonfile.json", "r") as jsonFile: # Opens Json file for reading
	data = json.load(jsonFile) # Reads Json file using json.load() method
'''
Example Json File:
[{"name": "Bill", "age": 20},
{"name": "Mary", "age": 31},
{"name": "Jake", "age": 19}]
'''
data[1]["age"] = 32 # Alters data variable
''' 
Now the data variable is:
[{"name": "Bill", "age": 20},
{"name": "Mary", "age": 32},
{"name": "Jake", "age": 19}]
'''
with open("jsonfile.json", "w") as fileJson: # Opens Json file once again
  json.dump(data, fileJson) # Replaces the Json file using json.dump() method
Posted by: Guest on September-03-2020
0

python get value from json

for key, value in data.items():
    print key, value
Posted by: Guest on March-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language