import json with open('path_to_file/person.json') as f: data = json.load(f) print(data)
import json x = '{ "name":"John", "age":30, "city":"New York"}' y = json.loads(x) print(y["age"])
import json json = """{ "name":"John", "age":30, "city":"New York" }""" # parse x: y = json.loads(json)
import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x)
# a Python object (dict): x = { "name": "John", "age": 30, "city": "New York" } # convert into JSON: y = json.dumps(x)
import json x = { "name": "John", "age": 30, "city": "New York" } y = json.dumps(x)
my_string = '[{"name": "sarah", "grade": 10}]' # create json my_json_string = json.loads(my_string) # turn it in a dictionary print(my_json_string[0]['name']) # [0] in list we have to assess to the related element
json.dumps(x, indent=4, separators=(". ", " = "))