Check that a JSON boolean stays a boolean
Use the opposite Shift key for paired punctuation. · 164 words
A JSON boolean must be the unquoted words true or false. Quoting them creates a string that can break code expecting a yes/no decision. A bookstore source says: title, Atlas of Birds; format, paperback; available, yes. Prompt: "Return one JSON object with title (string), format (string), and in_stock (boolean). Convert yes to true and no to false. Output only JSON, with no code fences or explanation." Expected result: {"title":"Atlas of Birds","format":"paperback","in_stock":true}. The prompt gives the allowed type and a direct value mapping.
A second record tests the opposite case: title, City Maps; format, hardcover; available, no. Its result should be {"title":"City Maps","format":"hardcover","in_stock":false}. Parse the output and check typeof result.in_stock equals "boolean", not "string". Also check that the first record produces true and the second produces false. This catches the common mistake of returning "true" because it looks JSON-like, although it is text. If the app uses an API schema, require the boolean type there too, so invalid strings are rejected before the code runs.
Check your recall
After parsing {"in_stock":"true"}, what is the problem, and what should the value be?
Check your answer
The value is a string because it is quoted. A JSON boolean must be written as the unquoted value true.
Sources and credits
Original KeyTouch lesson. Background reading · JSON Schema · Understanding JSON Schema.