针对XML Schema(XSD)验证JSON [英] Validate JSON against XML Schema (XSD)

查看:182
本文介绍了针对XML Schema(XSD)验证JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java中验证JSON和XSD?我有一个应用程序,我收到JSON响应,我想对现有的XSD进行验证。我的应用程序的另一部分使用XML,这就是为什么如果它们都可以对现有的XSD进行验证最简单的原因。

解决方案

XML Schema(XSD)用于验证 XML ;要验证 JSON ,请参阅 JSON Schema



我建议手动生成模式以充分理解和完整控制约束。但是,以下是一些可以快速启动该过程的自动化工具:




  • 要从JSON Schema转换为XSD,请参阅 jsons2xsd

  • 要从XSD转换为JSON架构,请参阅


    相关且非常有用:




    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:

    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆