ISO20022 — XSD to JSON Schema [PART 5]
Background
In this article we will discuss generating a ISO20022 JSON Schema from a XSD Schema.
There have been other tools that help with this task. However i wanted to test the waters by coding this myself.
This is the fifth article in a five part series
Part Five — This Article
Code
The code i have written is Kotlin code for JSON Schema Creation from XSD Schema and is available here .
XSD Schemas used
Two XSD Schemas have been taken from the website https://www.iso20022.org/iso-20022-message-definitions?business-domain=1
You can see the files here: One is pacs.008.001.09.xsd and the other is camt.050.001.05
JSON Schemas Created
The Created JSON Schemas are visible here : One is pacs.008.001.09.schema.json and the other is camt.050.001.05.schema.json
Comparison
Lines of Schema— XSD has less lines
There seems to be almost double the lines of code in the JSON Schemas as compared to the XSD Schemas
Name Spaces — JSON has less (Possible Loss of context ?)
JSON has just the id and schema attributes. One of them “Schema” is used for the version of JSON schema, so only one id attribute out of the box for namespaces.
When converting from an XSD schema there could be loss of context as ISO20022 Schema does have many namespaces as a normal aspect of an XSD schema.
XSD has many names-spaces for example
<xs:schema xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.09" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.09">
JSON has only two attribute for namespaces
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.09"
Unbounded elements — XSD has unbounded JSON Schema does not have this
XSD can have unbounded types
<xs:element maxOccurs="unbounded" minOccurs="0" name="ChrgsInf" type="Charges7"/>
JSON cannot have unbounded types
"ChrgsInf": {
"minItems": 0,
"maxItems": 999,
"type": "array",
"items": {
"$ref": "#/definitions/Charges7"
}
},
Code to change unbounded to 999
MAXOCCURS ->
when {value.equals(UNBOUNDED, ignoreCase = true) -> complexElement.maximum = 999
else -> complexElement.maximum = Integer.valueOf(value)}
XSD Composition vs JSON Composition
- XSD has clear composition with simple and complex types with clear choices and sequences
- in JSON Schema, we could build similar structures though they look forced and may not build up quite as well
XSD — Composition with sequence and complex types
<xs:complexType name="Charges7">
<xs:sequence>
<xs:element name="Amt" type="ActiveOrHistoricCurrencyAndAmount"/>
<xs:element name="Agt" type="BranchAndFinancialInstitutionIdentification6"/>
</xs:sequence>
</xs:complexType>
JSON — Supports composition with objects and references but no sequence
"Charges7": {
"type": "object",
"properties": {
"Amt": {
"$ref": "#/definitions/ActiveOrHistoricCurrencyAndAmount"
},
"Agt": {
"$ref": "#/definitions/BranchAndFinancialInstitutionIdentification6"
}
},
Conclusion
Please do have a look at the Gitlab code here. By all means feel free to contribute if you would like to do so. Leave me a comment here so i know.
XSD and JSON are built at different times and maybe for different purposes.
Fitting an ISO20022 Schema in to a JSON Schema may not convey the same aspects and in some cases we may even loose some information e.g. namespaces, unbounded elements and the like.
Careful considerations may be needed to make sure that the same business context is conveyed when moving from a XSD Schema to a JSON Schema.