JSON schema
August 23, 2023 ยท View on GitHub
Documentation
- JSON Schema: http://json-schema.org
- Understanding JSON Schema: https://spacetelescope.github.io/understanding-json-schema/
Guidelines
These guidelines are also related to the layout charter, specifically the form design section.
:warning: Form options shoud be documented, somewhere.
Order
Properties are ordered like this:
- title
- description
- type
- default (Default value)
- Constraints (e.g. minLength or pattern or minItems)
- additionalProperties (Only for objects)
- properties (Only for objects)
- propertiesOrder (Only for objects)
- required (Only for objects)
- items (Only for arrays)
- form (Editor specific behavior)
$schema property
- Mandatory.
Key names
- Snake case is the main rule:
snake_caseinstead ofcamelCase. - Except when the key name (ie field name) is inspired from BIBFRAME. This is the case with documents, as specified by the metadata working group.
Title
- Title is the natural language form of the property.
- It does not have any punctuation mark.
- In English and French, only the first word has a capitalized initial!
Description
- A description is optional.
- If used, it should add information to the title.
- It's considered as a form help for the end user.
- It's a sentence, it begins with a capital letter and ends with a punctuation mark.
- In English, only the first word has a capitalized initial.
String
- Always set the
minLengthandmaxLengthproperty. Adapt the ES mapping accordingly (see ES doc onignore_above) - If the
patternproperty is set and requires at least one character, theminLengthproperty is not mandatory.
Array
- Arrays always set the
minItemsproperty.
How to handle plurals
In the following example, the main key is singular, but its title is plural,
as it is the label in the editor, which will contain a list of elements.
On the contrary, the title of the array items is singular, as it is the
label of each item of the list.
The same logic would apply to the description if any where there.
"language": {
"title": "Languages",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "object",
"title": "Language",
"required": [
"type",
"value"
],
"additionalProperties": false,
"propertiesOrder": [
"type",
"value"
],
"properties": {
"type": {
"title": "Type",
"description": "Type of the language.",
"type": "string",
"default": "bf:Language",
"enum": [
"bf:Language"
],
"form": {
"hideExpression": "true",
"options": [
{
"label": "bf:Language",
"value": "bf:Language"
}
]
}
},
"value": {
"$ref": "#/definitions/language"
}
}
}
}
Enum
- For values, apply the following rules to ease the translation work:
- Use a standard controlled vocabulary if possible. Example: RDA values
- Use a prefix to identify the vocabulary, and separate it from the value with colon
: - Example for RDA mode of issuance:
rdami:1001. "rdami" refers to a URI.
- Use a prefix to identify the vocabulary, and separate it from the value with colon
- If no standard controlled vocabulary exists
- use natural language, or
- create home made codes, if the values need specific translations that should not be confused with others.
- add a home made prefix spearated by underscore
_in the case of a list bigger than 8-10 values or if the code is too short (like sz for Switzerland). - Example of a home made code with prefix for Switzerland:
country_sz. - Example of a home made code without prefix:
received_and_complete_or_ceased
- add a home made prefix spearated by underscore
- Use a standard controlled vocabulary if possible. Example: RDA values
- Form options:
- Use the
value/labelmethod only if the codes need to be translated. - In the
labelvalue, use the same value as the one of thevaluekey. This is to avoid translating the label and the value, as it is sometimes needed. - In case of a list and sublist with
oneOf(ex: main type/subtype), use the same text fortitleof the 1st-level element, as forvalueandlabel. This will ease the translations.
- Use the