Make an unknown value explicit in JSON

Use the opposite Shift key for paired punctuation. · 181 words

When a field can be unknown, name the exact JSON value to use. In JSON, null means no value was supplied. It differs from an empty string or the text "unknown". A library record gives title, Small Gardens, and author, Mina Lee, but no subtitle. Prompt: "Return one JSON object with title (string), author (string), and subtitle (string or null). If the source omits a value, use null. Never guess or write unknown. Output only JSON." The result is {"title":"Small Gardens","author":"Mina Lee","subtitle":null}. This marks the missing subtitle clearly.

A second record shows when null would be wrong: title, Atlas of Skies; author, Ravi Shah; subtitle, A Practical Guide. The result is {"title":"Atlas of Skies","author":"Ravi Shah","subtitle":"A Practical Guide"}. Parse both objects and require subtitle to be either null or a string. Also require the first subtitle to equal null and the second to equal "A Practical Guide". These checks expose two errors: replacing an unknown with a guess, and using null when the source supplied a value. State the null rule inside the prompt so the output stays consistent across many records.

Check your recall

What JSON value should represent an omitted library subtitle, and what should the prompt forbid?

Check your answer

Use null. Forbid guessing, writing the text "unknown", and using an empty string as a substitute for a missing value.

Sources and credits

Original KeyTouch lesson. Background reading · JSON Schema · Understanding JSON Schema.