-
json 읽기 / 쓰기python/응용 2022. 5. 31. 16:31
import json s = { "employ": [ {"id": 1, "name": "Mike"}, {"id": 2, "name": "Nancy"} ] } print(s) # json.dumps: returns a string representing a json object from an object json_dumps = json.dumps(s) print(json_dumps) # json.loads: returns an object from a string representing a json object print(json.loads(json_dumps)) # write to file with open('test.json', 'w') as f: json.dump(s, f) # read from file with open('test.json', 'r') as f: print(json.load(f))
'python > 응용' 카테고리의 다른 글
Raw SQL & SQLAlchemy 예제 (0) 2022.07.04 requests (0) 2022.05.31 pytest - fixture (0) 2022.05.23 pytest - basic (0) 2022.05.23 Thread - queue & PoisonPill (0) 2022.05.23