Validate JSON against XML Schema (XSD)

user16655 picture user16655 · Mar 22, 2016 · Viewed 21.4k times · Source

Is it possible to validate JSON with an XSD in Java? I have an application where I receive JSON response, and I would like to validate it against existing XSD. Another part of my application uses XML, which is why it would be easiest if they both could validate against the existing XSD.

Answer

kjhughes picture kjhughes · Mar 22, 2016

No, XML Schema (XSD) is for validating XML; to validate JSON, see JSON Schema.

I recommend generating schemas by hand for full understanding and full control over the constraints. However, here are some automated tools that can jumpstart the process:

Related and also very useful:

  • To parse from XML to JSON (unmarshal) or serialize JSON to XML (marshal), see JSONIX.
  • For a list of implementations, including validators in various languages, see JSON-Schema Implementations.