Escape a quotation mark in a string
Use the opposite Shift key for paired punctuation. · 211 words
Structured output starts with a fixed data contract. For a bookshop catalog, give this source: title = The Glass Hour; note = The reader said "send one copy." Ask for one JSON object with keys title and note, valid JSON, and no code fences. In the note string, each quotation mark must become a backslash followed by a quote (\" in JSON text). The expected value is {"title":"The Glass Hour","note":"The reader said \"send one copy.\""}. Check the result with a JSON parser, then compare the decoded note with the source, including both quotation marks.
Try a different source to test the same rule: artist = Ana Lee; label = The guide called the painting "bold" and "simple". Add these lines to the prompt: Preserve the source exactly, use straight quotation marks, and escape every quotation mark inside a string as backslash plus quote. Do not return Markdown. The output should contain the same artist and label, with four escaped quote characters in the label. Parse the output, not just its appearance. Then verify that the decoded label still contains the phrases "bold" and "simple" and that both words are enclosed by quotation marks. A parser error means the escaping failed. A successful parse with changed wording means the preservation instruction failed.
Check your recall
How should an embedded double quotation mark be encoded in a JSON string, and how can you confirm that it was handled correctly?
Check your answer
Encode it as one backslash followed by one double quotation mark. First parse the complete response as JSON; then compare the decoded string with the source to confirm that both quotation marks remain.
Sources and credits
Original KeyTouch lesson. Background reading · JSON Schema · Understanding JSON Schema.