딕셔너리 형태를 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"
}
'파이썬' 카테고리의 다른 글
property 데코레이터 (0) | 2024.09.10 |
---|---|
파이썬 함수(is, ==의 차이/ 바다코끼리/ suppress[try catch] / big num) (0) | 2024.08.29 |
파이썬에서의 모듈러 연산(음의 정수) (0) | 2024.08.02 |
reverse iterator등의 Iterator 유의점 (0) | 2024.07.17 |
AI 웹 개발 공부 3일 차 (사전 캠프) (0) | 2024.05.31 |