파이썬

python에서 json파일을 읽을 때 '한글' 도 읽는 방법

zhelddustmq 2024. 9. 25. 17:46

딕셔너리 형태를 json string으로 변환해주는 함수: json.dumps

import json 

# 예
temp_dict = {
    'abcdefghi123': '김진영qwerty456'
}

# ensure_ascii가 True이면, ascii가 아닌, 다른 문자들은 모두 이스케이프 문자로 출력
print(json.dumps(temp_dict, indent=4, ensure_ascii=True))
print("==")
# 반면, ensure_ascii를 False로 하면, 아스키에 포함되지 않는 문자들도 출력
print(json.dumps(temp_dict, indent=4, ensure_ascii=False))

 

------------------------------------------------

{
    "abcdefghi123": "\uae40\uc9c4\uc601qwerty456"
}
==
{
    "abcdefghi123": "김진영qwerty456"
}