]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
🌐 Add Korean translation for Tutorial - JSON Compatible Encoder (#3152)
authorKwang Soo Jeong <clax1412@outlook.com>
Wed, 8 Dec 2021 15:43:31 +0000 (00:43 +0900)
committerGitHub <noreply@github.com>
Wed, 8 Dec 2021 15:43:31 +0000 (16:43 +0100)
docs/ko/docs/tutorial/encoder.md [new file with mode: 0644]

diff --git a/docs/ko/docs/tutorial/encoder.md b/docs/ko/docs/tutorial/encoder.md
new file mode 100644 (file)
index 0000000..8b5fdb8
--- /dev/null
@@ -0,0 +1,34 @@
+# JSON ν˜Έν™˜ κ°€λŠ₯ μΈμ½”더
+
+데이터 μœ ν˜•(예: Pydantic λͺ¨λΈ)을 JSONκ³Ό ν˜Έν™˜λœ ν˜•νƒœλ‘œ λ°˜ν™˜ν•΄μ•Ό ν•˜λŠ” κ²½μš°κ°€ μžˆμŠ΅λ‹ˆλ‹€. (예: `dict`, `list` λ“±)
+
+예λ₯Ό λ“€λ©΄, λ°μ΄ν„°λ² μ΄μŠ€μ— μ €μž₯ν•΄μ•Όν•˜λŠ” κ²½μš°μž…λ‹ˆλ‹€.
+
+이λ₯Ό μœ„ν•΄, **FastAPI** μ—μ„œλŠ” `jsonable_encoder()` ν•¨μˆ˜λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.
+
+## `jsonable_encoder` μ‚¬μš©
+
+JSON ν˜Έν™˜ κ°€λŠ₯ λ°μ΄ν„°λ§Œ μˆ˜μ‹ ν•˜λŠ” `fake_db` λ°μ΄ν„°λ² μ΄μŠ€κ°€ μ‘΄μž¬ν•œλ‹€κ³  κ°€μ •ν•˜κ² μŠ΅λ‹ˆλ‹€.
+
+예λ₯Ό λ“€λ©΄, `datetime` κ°μ²΄λŠ” JSONκ³Ό ν˜Έν™˜λ˜λŠ” λ°μ΄ν„°κ°€ μ•„λ‹ˆλ―€λ‘œ μ΄ λ°μ΄ν„°λŠ” λ°›μ•„λ“€μ—¬μ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
+
+λ”°λΌμ„œ `datetime` κ°μ²΄λŠ” <a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">ISO format</a> λ°μ΄ν„°λ₯Ό ν¬ν•¨ν•˜λŠ” `str`둜 λ³€ν™˜λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.
+
+같은 λ°©μ‹μœΌλ‘œ μ΄ λ°μ΄ν„°λ² μ΄μŠ€λŠ” Pydantic λͺ¨λΈ(속성이 μžˆλŠ” κ°μ²΄)을 λ°›μ§€ μ•Šκ³ , `dict` λ§Œμ„ λ°›μŠ΅λ‹ˆλ‹€.
+
+이λ₯Ό μœ„ν•΄ `jsonable_encoder` λ₯Ό μ‚¬μš©ν•  μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.
+
+Pydantic λͺ¨λΈκ³Ό κ°™μ€ κ°μ²΄λ₯Ό λ°›κ³  JSON ν˜Έν™˜ κ°€λŠ₯ν•œ λ²„μ „μœΌλ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€:
+
+```Python hl_lines="5  22"
+{!../../../docs_src/encoder/tutorial001.py!}
+```
+
+이 μ˜ˆμ‹œλŠ” Pydantic λͺ¨λΈμ„ `dict`둜, `datetime` ν˜•식을 `str`둜 λ³€ν™˜ν•©λ‹ˆλ‹€.
+
+μ΄λ ‡κ²Œ ν˜ΈμΆœν•œ κ²°κ³ΌλŠ” νŒŒμ΄μ¬ ν‘œμ€€μΈ <a href="https://docs.python.org/3/library/json.html#json.dumps" class="external-link" target="_blank">`json.dumps()`</a>둜 μΈμ½”λ”© ν•  μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.
+
+길이가 κΈ΄ λ¬Έμžμ—΄ ν˜•νƒœμ˜ JSON ν˜•식(λ¬Έμžμ—΄)의 λ°μ΄ν„°κ°€ λ“€μ–΄μžˆλŠ” μƒν™©μ—μ„œλŠ” `str`둜 λ°˜ν™˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. JSONκ³Ό λͺ¨λ‘ ν˜Έν™˜λ˜λŠ” κ°’κ³Ό ν•˜μœ„ κ°’이 μžˆλŠ” Python ν‘œμ€€ λ°μ΄ν„° κ΅¬μ‘° (예: `dict`)λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
+
+!!! note "μ°Έκ³ "
+    μ‹€μ œλ‘œ `jsonable_encoder`λŠ” **FastAPI** μ—μ„œ λ‚΄λΆ€μ μœΌλ‘œ λ°μ΄ν„°λ₯Ό λ³€ν™˜ν•˜λŠ” λ° μ‚¬μš©ν•˜μ§€λ§Œ, λ‹€λ₯Έ λ§Žμ€ κ³³μ—μ„œλ„ μ΄λŠ” μœ μš©ν•©λ‹ˆλ‹€.