针对XML Schema(XSD)验证JSON [英] Validate JSON against XML Schema (XSD)
问题描述
是否可以在Java中验证JSON和XSD?我有一个应用程序,我收到JSON响应,我想对现有的XSD进行验证。我的应用程序的另一部分使用XML,这就是为什么如果它们都可以对现有的XSD进行验证最简单的原因。
否, XML Schema(XSD)用于验证 键 XML 强> ;要验证 JSON ,请参阅 JSON Schema 。
我建议手动生成模式以充分理解和完整控制约束。但是,以下是一些可以快速启动该过程的自动化工具:
- 要从JSON Schema转换为XSD,请参阅 jsons2xsd 。
- 要从XSD转换为JSON架构,请参阅
相关且非常有用:
- 从XML解析为JSON(unmarshal)或将JSON序列化为XML
( marshal),请参阅 JSONIX 。 - 有关实施的列表,包括各种语言的验证器,请参阅 JSON-Schema实施。
Is it possible to validate JSON 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.
解决方案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.
这篇关于针对XML Schema(XSD)验证JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 从XML解析为JSON(unmarshal)或将JSON序列化为XML