JSON-schema to XML schema converter written in Java.
<dependency>
<groupId>com.ethlo.jsons2xsd</groupId>
<artifactId>jsons2xsd</artifactId>
<version>2.3.1</version>
</dependency>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
try (final Reader r = ...)
{
final Config cfg = new Config.Builder()
.targetNamespace("http://example.com/myschema.xsd")
.name("array")
.build();
final Document doc = Jsons2Xsd.convert(r, cfg);
}
{
"type":"array",
"items":{
"type":"object",
"properties":{
"price":{
"type":"number",
"minimum":0
},
"name":{
"type":"string",
"minLength":5,
"maxLength":32
},
"isExpired":{
"default":false,
"type":"boolean"
},
"manufactured":{
"type":"string",
"format":"date-time"
}
},
"required":[
"price",
"name",
"manufactured"
]
}
}
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:x="http://example.com/myschema.xsd" elementFormDefault="qualified" targetNamespace="http://example.com/myschema.xsd">
<complexType name="array">
<sequence>
<element name="price">
<simpleType>
<restriction base="decimal">
<minInclusive value="0" />
</restriction>
</simpleType>
</element>
<element name="name">
<simpleType>
<restriction base="string">
<minLength value="5" />
<maxLength value="32" />
</restriction>
</simpleType>
</element>
<element minOccurs="0" name="isExpired" type="boolean" />
<element name="manufactured" type="dateTime" />
</sequence>
</complexType>
</schema>
final Config cfg = new Config.Builder()
.ignoreUnknownFormats(true)
...
.build();
final Config cfg = new Config.Builder()
.customTypeMapping(JsonSimpleType.INTEGER, "int64", XsdSimpleType.LONG)
.customTypeMapping(JsonSimpleType.INTEGER, "int32", XsdSimpleType.INT)
.customTypeMapping(JsonSimpleType.STRING, "ext-ref", XsdSimpleType.STRING)
...
.build();
final Config cfg = new Config.Builder()
.nonJsonTypeMapping("date-time", XsdSimpleType.DATE_TIME)
.nonJsonTypeMapping("int", XsdSimpleType.INT)
...
.build();