Does anybody know how to generate a JSON schema from a existing XML schema (XSD file)? Are there any tools available for this?
This question is related to
xml
json
xsd
transform
jsonschema
JSON Schema is not intended to be feature equivalent with XML Schema. There are features in one but not in the other.
In general you can create a mapping from XML to JSON and back again, but that is not the case for XML schema and JSON schema.
That said, if you have mapped a XML file to JSON, it is quite possible to craft an JSON Schema that validates that JSON in nearly the same way that the XSD validates the XML. But it isn't a direct mapping. And it is not possible to guarantee that it will validate the JSON exactly the same as the XSD validates the XML.
For this reason, and unless the two specs are made to be 100% feature compatible, migrating a validation system from XML/XSD to JSON/JSON Schema will require human intervention.
Copy your XML schema here & get the JSON schema code to the online tools which are available to generate JSON schema from XML schema.
True, but after turning json to xml with xmlspy, you can use trang application (http://www.thaiopensource.com/relaxng/trang.html) to create an xsd from xml file(s).
Disclaimer: I'm the author of jgeXml.
jgexml has Node.js based utility xsd2json
which does a transformation between an XML schema (XSD) and a JSON schema file.
As with other options, it's not a 1:1 conversion, and you may need to hand-edit the output to improve the JSON schema validation, but it has been used to represent a complex XML schema inside an OpenAPI (swagger) definition.
A sample of the purchaseorder.xsd given in another answer is rendered as:
"PurchaseOrderType": {
"type": "object",
"properties": {
"shipTo": {
"$ref": "#/definitions/USAddress"
},
"billTo": {
"$ref": "#/definitions/USAddress"
},
"comment": {
"$ref": "#/definitions/comment"
},
"items": {
"$ref": "#/definitions/Items"
},
"orderDate": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}.*$"
}
},
Source: Stackoverflow.com