Skip to main content

Validate JSON according XSD schema

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
edrozim
Offline
Joined: 2010-09-09

Hi,

Some site have REST API that return responses in two formats : xml and JSON .
Currently I finished basic checks for xml responses of this API .

Idea was simple - validate xml response using existing xsd schema that clear define what should be inside . I use Jersey (
http://jersey.java.net/ ) for "speaking" with API and SAX to validate responses.

Now I need to do the same for JSON format . First big problem here is that I don't have JSON Schema to validate JSON response . So only way that I see is unmarshall JSON response to POJO hierarchy and then validate it against xsd that I have . But this way also raise up hard questions : I can't find Java classes that allow me to do this automatically . Also I can't find classes that allow me to work with xsd in low level - I mean not just general "tell me if this xml is valid according this xsd" but "tell me if this tag can have such children with such types".

Any ideas , directions or just thoughts are welcome. Maybe somebody can suggest totally different way ? Or somebody can suggest classes that allow to work with xsd on low level ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kubatzki
Offline
Joined: 2011-03-25

just an idea ,,, convert json to xml and validate it agains xsd . ?.

sla31
Offline
Joined: 2011-06-23

Hello edrozim,

Have you found a solution for your problem without convert JSON to XML ?

Best regards,

Sla31