Validate JSON against XML Schema (XSD)

做~自己de王妃 提交于 2019-12-04 18:47:08

问题


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.


回答1:


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:

  • To convert from JSON Schema to XSD, see jsons2xsd.
  • To convert from XSD to JSON Schema, see Jsonix Schema Compiler.

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.



回答2:


No, the standards are different between the two.

But if you really want to rely on the xsd for validating, Jsonix Schema Compiler can help you generate a JSON Schema to validate your json from your XML Schema.



来源:https://stackoverflow.com/questions/36152972/validate-json-against-xml-schema-xsd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!