A standards-compliant JSON Schema (2020-12) validator for MoonBit, with precise error paths and full error collection.
Dependencies
| 指标 | 结果 |
|---|---|
| 测试用例 | 1307 / 1307 通过(100%) |
| 未纳入 | 1 例需 $vocabulary 语义支持(见下),另有 refRemote.json 需真实 HTTP 服务 |
let schema = @json.parse("{\"type\": \"integer\", \"minimum\": 0}")
let instance = @json.parse("42")
inspect(@jsonschema.is_valid(schema, instance), content="true")match @jsonschema.validate(schema, instance) {
Ok(_) => // valid
Err(errors) =>
for e in errors {
// e.instance_path: "/users/0/age"
// e.schema_path: "#/properties/users/items/properties/age/type"
// e.keyword: "type"
// e.message: "expected integer, got string"
}
}match @jsonschema.validate_json(schema_text, instance_text) { ... }let docs : Map[String, Json] = Map([])
docs.set("https://example.com/defs.json", @json.parse(defs_text))
@jsonschema.validate_with_docs(schema, instance, docs)$ moon run cmd/main -- "$(cat schema.json)" "$(cat instance.json)"
invalid at /age: -1 is less than minimum 0 (minimum at #/properties/age/minimum)moon check # static checks
moon fmt # format
moon test # unit tests + full official conformance suite
moon run cmd/main # run the CLI
python tools/gen_suite.py # regenerate suite tests from fixturespub(all) enum JsonSchemaError {
SchemaParseError(String)
InstanceParseError(String)
ValidationErrors(Array[ValidationError])
} derive(Debug)Install
Download zipA standards-compliant JSON Schema (2020-12) validator for MoonBit, with precise error paths and full error collection.
Dependencies