Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert XSD to JSON schema directly in Java

can anybody suggest how to convert XSD schema to JSON schema using Java?

I have tried so many ways, almost all the ways generating class files using com.fasterxml.jackson libraries and then converting it to JSON which is not possible in my case.

here are the links I have tried

https://dzone.com/articles/generating-json-schema-xsd

http://marxsoftware.blogspot.in/2015/06/json-schema-xsd-jaxb-jackson.html

Thanks in Advance.

like image 882
Venkatesh K Avatar asked Aug 02 '17 12:08

Venkatesh K


People also ask

How do you convert XSD to JSON Schema?

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 is the use of XSD file in Java?

xsd is the XML schema you will use as input to the JAXB binding compiler, and from which schema-derived JAXB Java classes will be generated. For the Customize Inline and Datatype Converter examples, this file contains inline binding customizations.


1 Answers

Follow below steps to directly transform XSD into JSON Schema using Jsonix library

  1. Download jsonix schema compiler from here

    The downloaded jar name would be something like below based on downloaded version
    jsonix-schema-compiler-full-2.3.9.jar

  2. Open command prompt or linux shell and navigate to the above jar directory.

  3. Execute below command from this directory
    java -jar jsonix-schema-compiler-full-2.3.9.jar -generateJsonSchema -p FOOD schemas/food.xsd
    Note: in above command schemas/food.xsd is the relative path of XSD schema file

  4. Above step will generate two files in the current directory
    a. schema file (FOOD.jsonschema)
    b. mapping file (FOOD.js)

  5. The schema file with .jsonschema extenstion is the desired equivalent JSON Schema.

like image 63
sapan prajapati Avatar answered Oct 03 '22 20:10

sapan prajapati