Convert XML Schema to/from JSON Schema
If the active document is an XML Schema, this command generates a JSON schema document from the XML schema. If the active document is a JSON schema, the command generates an XML Schema from the JSON schema. The generated document is opened in a new window, and can then be saved to any location. Conversion options are described below. For more information about JSON and JSON editing support in XMLSpy, see the section JSON and JSON Schema.
XML Schema to JSON Schema conversion options
When you click the Convert XML Schema to/from JSON Schema command to convert an XML Schema document to a JSON schema, the Convert XML Schema to JSON Schema dialog (screenshot below) appears. Select the JSON Schema version you want and the conversion options, and click OK. A JSON schema will be generated from the XML Schema, and the generated document will be opened in a new window.
The general conversion strategy is this: (i) XML Schema simple types are mapped to JSON Schema simple types (such as string and number); (ii) XML Schema complex types are mapped to JSON objects.
The top part of the dialog provides information about how certain XML Schema components are converted. The bottom part of the dialog provides the following options:
•Create a property named "#" in each subschema: If selected, a property with this name is created in each JSON schema definition for .
•Create pattern properties matching properties prefixed with '?', "@xsi", "@xmlns": Specifies, for each of these prefixes, a pattern property to match properties with names that have these prefixes. For more information about pattern properties, see the section JSON Objects and Properties.
•Always create arrays for particles with maxOccurs > 1: In XML Schema, particles are the elements of complex content models. If the number of occurrences is more than one, then the particles are defined as an array in JSON Schema. Otherwise, they are defined as properties of a JSON object.
•Create a pure object for complex types with simple content: XML Schema's complex type with simple content is a type that allows attributes and text content, but no child elements. If the Create pure object option is selected, then the complex type is converted to a JSON object. The type's attributes are converted to properties of the JSON object, where the property names are prefixed with @. For the type's text content, a property named $ is generated. If the Create pure object option is not selected, then the complex type is converted into an object that may contain other objects and JSON simple types such as string and number.
•Create a local schema for built-in type definitions: If selected, this option creates the type definition in the object itself. Otherwise, the type definition is a reference to a separate object. The two output cases are shown in the JSON Schema code fragments below.
Type definition is referenced:
"properties": {
"AccountManager": {
"$ref": "#/definitions/xs:string"
}
}
"xs:string": {
"type": "string"
}
Type definition is local:
"properties": {
"AccountManager": {
"type": "string"
}
}
•Simplify occurrence constraints: When this options is selected, (i) occurrences are simplified to required or optional and (ii) repeating elements are defined as arrays with unbounded maxItems.
•Create Format property if applicable: If selected, XML Schema datatypes are converted to corresponding JSON Schema formats if possible.
JSON Schema to XML Schema conversion options
When you click the Convert XML Schema to/from JSON Schema command to convert a JSON Schema document to an XML schema, the Convert JSON Schema to XML Schema dialog (screenshot below) appears. Set the conversion options you want, and click OK. An XML schema will be generated from the JSON Schema, and the generated document will be opened in a new window.
You can select the following options:
•Whether JSON property names that begin with '@' and '$' are created or not. They would be created, respectively, as attribute nodes and text nodes.
•Whether properties named '#' are created, as XML comment nodes, or not.
•Whether pattern properties that match properties prefixed with '?', "@xsi", and/or "@xmlns" are ignored or not. If not ignored, then the properties prefixed with '?', "@xsi", and "@xmlns" are converted, respectively, to processing instructions, xsi: prefixed attributes, and xmlns: prefixed attributes.
•Whether JSON Schema format properties are considered for conversion to the corresponding XML Schema datatypes.