Answers for "What function takes a string of JSON data and returns a Python data structure?"

1

response.json results in pretty data python

import requests
import json
r = requests.get('http://server.com/api/2/....')
pretty_json = json.loads(r.text)
print (json.dumps(pretty_json, indent=2))
Posted by: Guest on April-03-2020
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

Code answers related to "What function takes a string of JSON data and returns a Python data structure?"

Code answers related to "Javascript"

Browse Popular Code Answers by Language