如何从 Lua json 格式验证中获取所有错误

我能够使用如 ljsonschemarapidjason 等 Lua json 格式验证器,但是发现它们都不能给出所有错误信息,并且在发现第一个错误后就终止了。 如果输入的 json 有超过一个验证问题,是否可能获得完整的错误列表?

例如: 对于如下 schema:

{
  "type" : "object",
  "properties" : {
     "foo" : { "type" : "string" },
     "bar" : { "type" : "number" }
  }
}

样本 json:{ "foo": 12, "bar": "42" } 应该给出 2 个错误。然而,我只得到了 1 个错误:property "foo" validation failed: wrong type: expected string, got number

如何在同一次运行中获取以下两个错误:

  1. property "foo" validation failed: wrong type: expected string, got number
  2. property "bar" validation failed: wrong type: expected number, got string
点赞