Is there a tool to generate a JSON schema from an XML schema through Java? Is there a tool to generate a JSON schema from an XML schema through Java? xml xml

Is there a tool to generate a JSON schema from an XML schema through Java?


It isn't very elegant, but jackson can generate json schema from a java class . So you could take your xml schema, generate java classes from it with jaxb annotations, then generate the json schema from that as jackson supports jaxb annotations.


If you can get POJOs that match Schema (using xjc for example), you could then use Jackson to produce JSON Schema (see ObjectMapper.generateSchema(...)).


I'd expect you to be able to write an XSLT script that generated JSON structures from the XML schema fairly easily. This works because XSLT is prefectly happy to read and transform XML, and an XML schema is just XML.

Going the other way would be a bit harder. You need somthing that can read a JSON schema and spit out XML. For this you need a parser, and likely something that builds an AST of the parse. With that and a tree walk you're likely to be able to generate an XML schema fairly easily.

ANTLR will let you define grammars, build a parser and an AST fairly easily. It has some kind of "Structured Text" generator that might work for walking the AST.

Our DMS Software Reengineering Toolkit is like ANTLR but with more machinery. With DMS you can define the JSON syntax, build ASTs, and then write source-to-source tranformatinos to map that to XML representing your schema.