.json() in python code example
Example 1: print json python
import json
uglyjson = '{"firstnam":"James","surname":"Bond","mobile":["007-700-007","001-007-007-0007"]}'
parsed = json.loads(uglyjson)
print(json.dumps(parsed, indent=2, sort_keys=True))
Example 2: python json dump to file
import json
with open('data.json', 'w') as f:
json.dump(data, f)
Example 3: python json string to object
import json
x = '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)
print(y["age"])
Example 4: json python
import json
x = '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)
print(y["age"])
Example 5: Json in python
import json
json_file = json.load(open("your file.json", "r", encoding="utf-8"))
print(json_file)
Example 6: json load
import json
with open('path_to_file/person.json') as f:
data = json.load(f)