A lightweight, reusable JSON / API parameter validator with a CLI, written in MoonBit.
Dependencies
moon check # type-check the library and all packages
moon test # run the test suite
moon run examples/demo # run the demo (works on any backend)moon update# Windows (MSVC) or Linux/macOS
moon build cmd/main --target nativematch @MoonCheck.validate_strings(schema_text, data_text) {
Ok(errors) if errors.is_empty() => println("valid")
Ok(errors) =>
for error in errors {
println(@MoonCheck.to_string(error))
}
Err(reason) => println("could not validate: \{reason}")
}let schema = try { @MoonCheck.parse_schema_string(schema_text) } catch {
_ => panic("bad schema")
}
let data = try { @json.parse(data_text) } catch { _ => panic("bad json") }
if @MoonCheck.is_valid(schema, data) { ... }let results = [
@MoonCheck.FileResult::new("a.json", @MoonCheck.validate_text(schema, text_a)),
@MoonCheck.FileResult::new("b.json", @MoonCheck.validate_text(schema, text_b)),
]
let report = @MoonCheck.RunReport::new("schema.json", results)
println(@MoonCheck.render(report, @MoonCheck.ReportFormat::text(), false))
println(@MoonCheck.render(report, @MoonCheck.ReportFormat::json(), false)){
"type": "object",
"properties": {
"name": { "type": "string", "required": true, "minLength": 1, "maxLength": 30 },
"age": { "type": "int", "required": true, "min": 0, "max": 150 },
"role": { "type": "string", "required": false, "enum": ["admin", "user"] },
"tags": { "type": "array", "required": false, "maxItems": 5, "items": { "type": "string" } }
}
}| Key | Applies to | Meaning |
|---|---|---|
| type | all | The schema kind (required) |
| required | property | Property must be present (true) |
| enum | property | Value must equal one of the listed literals |
| min/max | int, number | Inclusive numeric bounds |
| minLength/maxLength | string | Character count bounds |
| minItems/maxItems | array | Element count bounds |
| items | array | Schema applied to every element (required) |
| properties | object | Map of property name → property schema |
{ "name": "", "age": 200, "role": "owner", "tags": ["a", "b"] }$.name: length must be at least 1, got 0
$.age: value must be at most 150, got 200
$.role: value must be one of ["admin","user"]
$.tags: length must be at most 5, got 4# one schema, one data file — valid: prints nothing, exits 0
mooncheck validate examples/cli/schema.json examples/cli/data_valid.json
# one schema, one data file — invalid: prints the errors, exits 1
mooncheck validate examples/cli/schema.json examples/cli/data_invalid.json
# -> $.action: value must be one of ["click","type","scroll"]
# $.x: value must be at least 0, got -5
# $.y: value must be at most 1080, got 5000mooncheck validate examples/cli/config.schema.json examples/cli/configs/*.jsonok: service_a.json
ok: service_b.json
service_c_broken.json: $.host: length must be at least 1, got 0
service_c_broken.json: $.port: value must be at most 65535, got 70000
service_c_broken.json: $.timeout: expected Int, got String
checked 3 document(s): 2 ok, 1 failed, 3 error(s){
"schema": "examples/cli/config.schema.json",
"ok": false,
"summary": { "checked": 3, "failed": 1, "errors": 3 },
"documents": [
{ "path": "service_a.json", "ok": true, "errors": [] },
{ "path": "service_b.json", "ok": true, "errors": [] },
{
"path": "service_c_broken.json",
"ok": false,
"errors": [
{ "path": "$.host", "kind": "too_short", "message": "length must be at least 1, got 0" },
{ "path": "$.port", "kind": "above_max", "message": "value must be at most 65535, got 70000" },
{ "path": "$.timeout", "kind": "type_mismatch", "message": "expected Int, got String" }
]
}
]
}mooncheck check-schema schema.json # lint a schema document on its own
mooncheck --help # usage
mooncheck --version # version
mooncheck validate s.json d.json -q # only report failures| Project | Focus | Interface |
|---|---|---|
| Betterlol/moon_zod | Zod/Pydantic-style runtime schemas for LLM tool calling: many kinds, combinators, strip/strict modes, JSON Schema export, prompt and struct-code generation | MoonBit code API; CLI that infers a schema from a sample |
| mizchi/jsonschema | JSON Schema (subset) validation plus MoonBit code generation | MoonBit code API |
| YumeCross/schema | Lightweight JSON Schema validation | MoonBit code API |
| MoonCheck | A schema-document-driven validator for checks and automation: a small fixed schema language, all-error collection with precise paths, and a batch/CI CLI | JSON schema documents + MoonBit library + CLI |
moon testMoonCheck/
├── moon.mod # module metadata
├── moon.pkg # root library package (no dependencies)
├── schema.mbt # schema type model (Type, specs, props)
├── schema_json.mbt # parse schema documents from JSON
├── validate.mbt # validation engine, validate_strings/validate_text
├── error.mbt # structured ValidationError / ErrorKind
├── report.mbt # text and JSON reports
├── cli.mbt # command line parsing + usage text
├── MoonCheck_test.mbt # black-box tests (public API)
├── MoonCheck_wbtest.mbt # white-box tests (engine internals)
├── cli_wbtest.mbt # white-box tests (CLI parsing + end-to-end flow)
├── report_wbtest.mbt # white-box tests (report rendering)
├── cmd/
│ └── main/ # CLI shell: reads files, prints, sets exit status
└── examples/
├── demo/ # runnable demo (moon run examples/demo)
└── cli/ # sample schemas + data (configs/ for batch runs)pub enum CliCommand {
Help
Version
Validate(ValidateOptions)
CheckSchema(CheckSchemaOptions)
Invalid(String)
} derive(Eq, Debug)pub struct NumSpec {
min : Double?
max : Double?
}pub struct StrSpec {
min_length : Int?
max_length : Int?
}pub struct ValidateOptions {
format : ReportFormat
quiet : Bool
schema : String
data : Array[String]
} derive(Eq, Debug){
"schema": "schema.json",
"ok": false,
"summary": { "checked": 2, "failed": 1, "errors": 2 },
"documents": [
{ "path": "a.json", "ok": true, "errors": [] },
{ "path": "b.json", "ok": false,
"errors": [ { "path": "$.age", "kind": "type_mismatch", "message": "..." } ] }
]
}fn validate_strings(schema_text : String, data_text : String) -> Result[Array[ValidationError], String]Install
Download zipA lightweight, reusable JSON / API parameter validator with a CLI, written in MoonBit.
Dependencies