一个自动化系统将为应用程序[Play with Scala] 提供 JSON,并且集成的合同是 JSON 不需要验证,因为它总是被认为是正确的。但是出于测试目的,当我们经常播种数据时,我们无法发送正确的 JSON。我们想根据一组语法来验证我们收到的 JSON。有没有一个图书馆已经这样做了。还是有更好的方法来做到这一点?
示例:有效 Json 的语法:
"header"->[String, mandatory],
"footer"->[String],
"someArray"->Array[String, mandatory],
"someArrayObject"->Array[
{
{"key1"->Int, mandatory},
{"key2"->String}
},
mandatory
]
和路过,
{
"header":"headerContent",
"footer":"footerContent",
"someArray":["str1", "str2"],
"someArrayObject"->[
{"key1":4, "key2":"someStringValue"},
{"key1":5, "key2":"someOtherStringValue"}
]
} // would pass
{
"header":"headerContent",
"footer":"footerContent",
"someArray":["str1", "str2"]
} // would notpass since someArrayObject though declared mandatory is not provided in the sample json