본문 바로가기
파이썬

json 파일 생성, 읽기, 수정

by zgabriel 2026. 1. 14.
728x90
반응형

1. 파일 생성하기

data = {
    "access_token":"",
    "access_token_date":"260113",
    "refresh_token":"",
    "refresh_token_date":"270101"
}

with open("token.json", "w", encoding="utf-8") as f:
    json.dump(data, f, ensure_ascii=False, indent=4)

print("생성완료")

 

2. 파일 읽기

with open("token.json", "r", encoding="utf-8") as f:
    data = json.load(f)

print(data["access_token"])

 

3. 파일 수정하기

with open("token.json", "r", encoding="utf-8") as f:
    data = json.load(f)

data["access_token_date"] = "260112"

with open("token.json", "w", encoding="utf-8") as f:
    json.dump(data, f, ensure_ascii=False, indent=4)

print("JSON 파일 수정 완료")

 

 

 

 

 

728x90
반응형

'파이썬' 카테고리의 다른 글

틱톡 토큰 갱신하기  (0) 2026.01.14
틱톡 토큰 발급받기  (0) 2026.01.14
조건문에서 널값 체크하기  (0) 2025.02.07
2차원 배열 모두 출력하기  (0) 2025.02.05
KoNLPy 설치하기 - 윈도우, 파이썬  (1) 2025.01.20