Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Is anyone aware of a tool or approach from which we can generate a JSON schema from XML schema or XML schema from JSON schema by Java?

like image 350
Harish Raj Avatar asked Oct 13 '11 12:10

Harish Raj


People also ask

How do you convert XSD to JSON?

Plugin for converting an XML Schema (XSD) file to a JSON Schema file. Once installed, go to Tools -> XML Actions, or right-click on an XML Schema file from Project view, and select "Convert XSD to JSON Schema".

What does @schema do in Java?

A Schema object is thread safe and applications are encouraged to share it across many parsers in many threads. A Schema object is immutable in the sense that it shouldn't change the set of constraints once it is created.

Does JSON have a schema like XML?

In the same way that an XML Schema specifies the structure and content of an XML document, a JSON schema specifies how the JSON data in a JSON document is organized. It specifies what data fields are expected and how the values are represented.

Is there an XSD for JSON?

Since JSON isn't there yet, the best option is to use one of the XML Schema languages. We can use an XSD to generate our Java object model. We can use the Java objects to export data into XML documents. We can even use the same Java objects to export the data into JSON documents.


2 Answers

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.

like image 140
sbridges Avatar answered Oct 05 '22 01:10

sbridges


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

like image 31
StaxMan Avatar answered Oct 04 '22 23:10

StaxMan