Validate JSON against XML Schema (XSD)(根据 XML Schema (XSD) 验证 JSON)
问题描述
是否可以在 Java 中使用 XSD 验证 JSON?我有一个接收 JSON 响应的应用程序,我想根据现有的 XSD 对其进行验证.我的应用程序的另一部分使用 XML,这就是为什么如果它们都可以针对现有的 XSD 进行验证将是最简单的.
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.
推荐答案
否, XML Schema (XSD) 用于验证 XML;要验证 JSON,请参阅 JSON 架构.
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:
- 要从 JSON Schema 转换为 XSD,请参阅 jsons2xsd.
- 要从 XSD 转换为 JSON Schema,请参阅 Jsonix Schema Compiler.
相关且非常有用:
- 从 XML 解析为 JSON(解组)或将 JSON 序列化为 XML(元帅),请参阅 JSONIX.
- 有关实现列表(包括各种语言的验证器),请参阅 JSON-Schema 实现.
这篇关于根据 XML Schema (XSD) 验证 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:根据 XML Schema (XSD) 验证 JSON
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
