Venkatesh K
Venkatesh K

Reputation: 721

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.

Upvotes: 6

Views: 13062

Answers (1)

sapan prajapati
sapan prajapati

Reputation: 1734

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.

Upvotes: 1

Related Questions