Document a JSON Schema: Annotations, Formatting and Safe Sharing
How to document a JSON Schema with annotations, formatting and generated docs: what each changes, what stays valid, and when a plain-text explanation is better.
Documenting a JSON Schema usually means one of three things: adding annotation keywords inside the schema, reformatting the file so people can read it, or generating separate human-readable documentation from it. Each is a transformation of text, and each carries a different risk to meaning. This review explains which approaches leave validation behavior intact, what each one changes, and how the result holds up when it is copied, shared or read with assistive technology.
Is documenting inside the schema the right approach?
For most teams, yes, within limits. Put explanations in annotation keywords and keep a consistently formatted copy of the schema as the single source of truth. The main benefit is that descriptions travel with the contract they describe, so they are less likely to drift out of date than a separate document. The decisive tradeoff is that the file grows longer and still reads as JSON rather than prose; readers who do not work with JSON will need a rendered view or a written summary.
Separate plain-text explanation is the better choice when you need to cover business rationale, workflows that span several schemas, or migration history; when the audience will not read JSON at all; or when the destination cannot be trusted to preserve exact characters, such as a word processor, slide deck or some chat tools. In those cases, write the explanation in prose and attach or link the schema file itself rather than pasting it inline.
What documenting a schema actually changes
The three approaches differ in whether they change the stored characters, the parsed value, or only the presentation. Adding annotations changes both the characters and the parsed schema, but not which documents validate. Reformatting changes stored characters but not the parsed value. Generating documentation changes neither; it produces a separate presentation layer that may or may not faithfully reflect the schema.
Annotation keywords
JSON Schema defines a set of keywords whose job is to describe data rather than constrain it. Adding or editing them does not by itself make any instance pass or fail validation. Some of these keywords were introduced in later drafts of the specification, so check which dialect your schema declares with its $schema keyword and confirm that your validator and tooling support it.
| Keyword | Purpose | Affects validation? |
| title | Short human-readable label | No |
| description | Longer explanation of meaning, rules or units | No |
| examples | Array of sample values | No |
| default | Documents a fallback value; validators do not insert it into data | No |
| deprecated | Marks a property that readers should stop using | No |
| readOnly / writeOnly | Signals which side of an exchange is expected to send the value | No |
| $comment | Notes for schema maintainers, not end users | No |
The example below adds documentation to a small schema. Every annotation could be removed and the same set of documents would still be valid. The example values are illustrative only.
{
"title": "Customer",
"description": "A customer record as returned by the accounts service.",
"type": "object",
"required": ["id", "email"],
"properties": {
"id": {
"type": "string",
"description": "Stable identifier. Never reused after deletion.",
"readOnly": true,
"examples": ["cus_8f2k1"]
},
"email": {
"type": "string",
"description": "Primary contact address."
},
"tier": {
"type": "string",
"enum": ["free", "pro"],
"default": "free",
"description": "Billing tier. The application treats a missing value as free."
},
"legacyCode": {
"type": "string",
"deprecated": true,
"description": "Kept for older clients; use tier instead."
}
},
"$comment": "Maintainers: keep the tier enum in sync with the billing table."
}
Two points are easy to get wrong. First, default is documentation: a validator will not fill in a missing value, so the description should say what the application does, as the tier example does. Second, JSON itself has no comment syntax, so lines starting with // or wrapped in /* */ will fail a strict parser. Use $comment for notes aimed at maintainers and description for anything a consumer of the schema should see; the specification intends $comment to stay out of user-facing output.
Formatting and pretty-printing
Whitespace between JSON tokens is insignificant, so pretty-printing and minifying change the stored characters without changing the parsed schema. Whitespace inside string values is different: it is part of the value, and a formatter should never touch it. The two snippets below parse to the same value; note that the description string is identical in both.
{"type":"object","properties":{"id":{"type":"string","description":"Stable identifier."}}}
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Stable identifier."
}
}
}
Reordering keys for readability is also safe in principle, because the JSON standard treats object members as unordered. In practice, reordering creates noisy diffs, and some documentation tools display properties in source order, so pick one ordering convention and keep it. Duplicate keys are a real hazard: the standard says names should be unique, but parsers differ in how they handle repeats, and a formatter may silently keep only one. Check for duplicates before formatting rather than after.
Generated documentation
Documentation generators read a schema and render it as HTML, Markdown or similar. This is a presentation change only; the schema file is not altered. The risk is fidelity. A generator may support only certain drafts, and constructs such as $ref, allOf, anyOf, oneOf and conditional subschemas are often simplified or flattened in the rendered view. Compare the output against the schema for those constructs before publishing it. No specific generator was evaluated for this review, so consult each tool's documentation for its supported dialects and keywords.
When "font" tools and character styling enter the picture
In text-tool vocabulary, a "font" generator often does not change a font at all; it substitutes different Unicode characters, such as mathematical bold or italic letters, that only look like styled versions of ordinary letters. That is a stored-character change. Applied to a property name or enum value, it produces a different string, so a key that looks like email will not match data containing the ordinary word email. Keep all schema keys and values in plain characters and apply any visual styling in the rendering layer, through Markdown or CSS in generated documentation. Reversing or mirroring text has no legitimate role in documenting a schema.
Will the schema stay readable and usable after copying or sharing?
Exact characters matter in JSON, and several common copy-and-paste hazards break schemas without any visible change. JSON accepts only the straight double quote as a string delimiter, so automatic conversion to curly quotes causes a parse error. Only the space, tab, line feed and carriage return count as whitespace between tokens, so a non-breaking space outside a string is also a parse error, while one inside a string silently changes the value. Zero-width characters can make two keys look identical when they are not. Trailing commas left over from hand editing are invalid in strict JSON. Which destinations introduce these problems depends on the product and its settings and was not tested for this review; treat them as hazards to check rather than certainties.
- Share the schema as a file or inside a code block, not as body text in a rich-text editor.
- Run the shared copy through a strict JSON parser and your schema validator after pasting it anywhere.
- Search for non-ASCII characters in keys and enum values if a key unexpectedly fails to match.
- Keep the formatted file under version control so any change to stored characters shows up in a diff.
For accessibility, raw JSON is readable but dense with punctuation, and how a screen reader voices that punctuation depends on the product and its verbosity settings; no assistive technology was tested for this review. Rendered documentation that uses real headings and tables with header cells generally gives assistive technology more structure to navigate, which is a general property of semantic HTML, but verify the actual output of whichever generator you use. Provide a plain-text equivalent when the readers are not developers, when the explanation will live in email or tickets, or when a rule depends on a regular expression in a pattern keyword, which is hard to read aloud; a sentence such as "must be five digits" is clearer than the pattern itself.
Descriptions stored in the schema remain searchable with ordinary text search, and editors that support JSON Schema commonly surface title and description as hover hints or autocompletion details; check your editor's documentation for which keywords it reads. Generated pages that place content in collapsed sections may not be fully found by in-page search, so confirm that important rules are visible without expanding anything.
Gaps in this review
No specific documentation generator, editor, sharing destination or assistive technology was tested. Statements about JSON syntax and annotation keywords reflect the published standards; statements about destinations and screen readers describe general risks to verify in your own environment, not measured results.