MoonBit-native RFC 8927 JSON Type Definition validator and code generator
moon add ppyj663/moonjtd@0.2.0git clone https://github.com/ppyj663/MoonJTD.git
cd MoonJTD
moon test --target js
moon run examples/quickstart --target jslet document = @jtd.parse_checked_schema(
"{\"properties\":{\"id\":{\"type\":\"uint32\"}}}",
)
match document {
Ok(schema) => {
let errors = @jtd.validate(schema, Json::object(Map([
("id", Json::number(7.0)),
])))
println(errors.length())
}
Err(errors) => for error in errors { println(error.to_string()) }
}///|
let user = @jtd.jtd_object()
.required("id", @jtd.jtd_uint32())
.required("name", @jtd.jtd_string())
.optional("email", @jtd.jtd_string())
.build()moon run examples/quickstart --target js
moon run examples/codegen --target jsmoonjtd --help
moonjtd check schema.jtd.json
moonjtd validate schema.jtd.json instance.json
moonjtd validate schema.jtd.json instance.json --format json
moonjtd generate schema.jtd.json RootType output.mbt
moonjtd inspect schema.jtd.json
moonjtd format schema.jtd.json output.json
moonjtd report schema.jtd.json
moonjtd report schema.jtd.json --format markdown report.mdMoonJTD/
├── *.mbt, moon.pkg # portable core library package
├── cmd/main/ # JavaScript CLI entry point
├── cmd/conformance/ # upstream RFC 8927 corpus runner
├── examples/ # runnable quickstart and code generation demos
├── fixtures/ # small, authored CLI smoke-test inputs
├── docs/ # design, standards, provenance, and history
├── scripts/ # CLI smoke checks, coverage, conformance, and audit
└── .github/workflows/ # multi-target continuous integrationmoon build --target js
moon build --target wasm-gc
moon fmt --check
moon check --target js
moon test --target js
moon check --target wasm-gc
moon test --target wasm-gc
moon check --target native
moon test --target native
moon coverage analyze
pwsh ./scripts/conformance.ps1
pwsh ./scripts/audit.ps1
pwsh ./scripts/cli-smoke.ps1
pwsh ./scripts/check-toolchain.ps1pub(all) suberror CodecError {
CodecInvalidSchema(Array[Diagnostic])
CodecInvalidJson(String)
CodecValidationFailed(Array[Diagnostic])
} derive(Eq, Debug)#deprecated("`CodecError::equal` is deprecated, use `Eq::equal` instead.")
fn CodecError::equal(CodecError, CodecError) -> Bool#deprecated("`CodecError::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn CodecError::not_equal(x : CodecError, y : CodecError) -> Bool#deprecated("`CodecError::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn CodecError::to_repr(CodecError) -> Repr#deprecated("`CodegenError::equal` is deprecated, use `Eq::equal` instead.")
fn CodegenError::equal(CodegenError, CodegenError) -> Bool#deprecated("`CodegenError::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn CodegenError::not_equal(x : CodegenError, y : CodegenError) -> Bool#deprecated("`CodegenError::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn CodegenError::to_repr(CodegenError) -> Repr#deprecated("`SchemaError::equal` is deprecated, use `Eq::equal` instead.")
fn SchemaError::equal(SchemaError, SchemaError) -> Bool#deprecated("`SchemaError::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn SchemaError::not_equal(x : SchemaError, y : SchemaError) -> Bool#deprecated("`SchemaError::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn SchemaError::to_repr(SchemaError) -> Repr#deprecated("`CodegenOptions::equal` is deprecated, use `Eq::equal` instead.")
fn CodegenOptions::equal(CodegenOptions, CodegenOptions) -> Boolfn CodegenOptions::new(root_name? : String, public_types? : Bool, derive_eq? : Bool, derive_debug? : Bool, header? : Bool) -> CodegenOptions#deprecated("`CodegenOptions::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn CodegenOptions::not_equal(x : CodegenOptions, y : CodegenOptions) -> Bool#deprecated("`CodegenOptions::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn CodegenOptions::to_repr(CodegenOptions) -> Reprpub(all) struct Diagnostic {
code : DiagnosticCode
message : String
instance_path : JsonPointer
schema_path : JsonPointer
} derive(Eq, Debug)#deprecated("`Diagnostic::equal` is deprecated, use `Eq::equal` instead.")
fn Diagnostic::equal(Diagnostic, Diagnostic) -> Boolfn Diagnostic::new(code : DiagnosticCode, message : String, instance_path? : JsonPointer, schema_path? : JsonPointer) -> Diagnostic#deprecated("`Diagnostic::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn Diagnostic::not_equal(x : Diagnostic, y : Diagnostic) -> Bool#deprecated("`Diagnostic::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn Diagnostic::to_repr(Diagnostic) -> Reprpub(all) enum DiagnosticCode {
InvalidJson
ExpectedObject
UnknownKeyword
MixedSchemaForms
InvalidMemberType
InvalidTypeName
EmptyEnum
DuplicateEnumValue
UnknownReference
NestedDefinitions
PropertyOverlap
InvalidDiscriminatorMapping
DuplicateDiscriminatorProperty
ValidationMismatch
MissingProperty
AdditionalProperty
InvalidDiscriminatorTag
UnknownDiscriminatorValue
ResourceLimitExceeded
InvalidIdentifier
GenerationFailure
} derive(Eq, Debug)#deprecated("`DiagnosticCode::equal` is deprecated, use `Eq::equal` instead.")
fn DiagnosticCode::equal(DiagnosticCode, DiagnosticCode) -> Bool#deprecated("`DiagnosticCode::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn DiagnosticCode::not_equal(x : DiagnosticCode, y : DiagnosticCode) -> Bool#deprecated("`DiagnosticCode::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn DiagnosticCode::to_repr(DiagnosticCode) -> Reprfn DiscriminatorSchemaBuilder::branch(self : DiscriminatorSchemaBuilder, tag_value : String, schema : Schema) -> DiscriminatorSchemaBuilderfn DiscriminatorSchemaBuilder::build(self : DiscriminatorSchemaBuilder) -> Result[Schema, Diagnostic]fn DiscriminatorSchemaBuilder::metadata_entry(self : DiscriminatorSchemaBuilder, name : String, value : Json) -> DiscriminatorSchemaBuilderfn DiscriminatorSchemaBuilder::nullable(self : DiscriminatorSchemaBuilder, nullable : Bool) -> DiscriminatorSchemaBuilder#deprecated("`DiscriminatorSchemaBuilder::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn DiscriminatorSchemaBuilder::to_repr(DiscriminatorSchemaBuilder) -> Reprfn DocumentBuilder::definition(self : DocumentBuilder, name : String, schema : Schema) -> DocumentBuilder#deprecated("`DocumentBuilder::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn DocumentBuilder::to_repr(DocumentBuilder) -> Repr#deprecated("`JsonPointer::equal` is deprecated, use `Eq::equal` instead.")
fn JsonPointer::equal(JsonPointer, JsonPointer) -> Bool#deprecated("`JsonPointer::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn JsonPointer::not_equal(x : JsonPointer, y : JsonPointer) -> Bool#deprecated("`JsonPointer::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn JsonPointer::to_repr(JsonPointer) -> Reprfn JtdCodec::decode_batch(self : JtdCodec, values : Array[Json]) -> Array[Result[ValidatedJson, CodecError]]fn JtdCodec::decode_json_array(self : JtdCodec, text : StringView) -> Result[Array[ValidatedJson], CodecError]fn JtdCodec::encode_json(self : JtdCodec, value : Json, escape_slash? : Bool) -> Result[String, CodecError]fn JtdCodec::encode_validated(self : JtdCodec, value : ValidatedJson, escape_slash? : Bool) -> Stringfn JtdCodec::new(document : SchemaDocument, options? : ValidationOptions) -> Result[JtdCodec, CodecError]fn ObjectSchemaBuilder::allow_additional(self : ObjectSchemaBuilder, allowed : Bool) -> ObjectSchemaBuilderfn ObjectSchemaBuilder::metadata_entry(self : ObjectSchemaBuilder, name : String, value : Json) -> ObjectSchemaBuilderfn ObjectSchemaBuilder::nullable(self : ObjectSchemaBuilder, nullable : Bool) -> ObjectSchemaBuilderfn ObjectSchemaBuilder::optional(self : ObjectSchemaBuilder, name : String, schema : Schema) -> ObjectSchemaBuilderfn ObjectSchemaBuilder::required(self : ObjectSchemaBuilder, name : String, schema : Schema) -> ObjectSchemaBuilder#deprecated("`ObjectSchemaBuilder::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn ObjectSchemaBuilder::to_repr(ObjectSchemaBuilder) -> Repr#deprecated("`PathSegment::equal` is deprecated, use `Eq::equal` instead.")
fn PathSegment::equal(PathSegment, PathSegment) -> Bool#deprecated("`PathSegment::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn PathSegment::not_equal(x : PathSegment, y : PathSegment) -> Bool#deprecated("`PathSegment::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn PathSegment::to_repr(PathSegment) -> Reprpub(all) struct Schema {
form : SchemaForm
nullable : Bool
metadata : Map[String, Json]
} derive(Debug)#deprecated("`SchemaCheckOptions::equal` is deprecated, use `Eq::equal` instead.")
fn SchemaCheckOptions::equal(SchemaCheckOptions, SchemaCheckOptions) -> Boolfn SchemaCheckOptions::new(max_depth? : Int, max_nodes? : Int, max_errors? : Int) -> SchemaCheckOptions#deprecated("`SchemaCheckOptions::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn SchemaCheckOptions::not_equal(x : SchemaCheckOptions, y : SchemaCheckOptions) -> Bool#deprecated("`SchemaCheckOptions::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn SchemaCheckOptions::to_repr(SchemaCheckOptions) -> Repr#deprecated("`SchemaDocument::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn SchemaDocument::to_repr(SchemaDocument) -> Repr#deprecated("`SchemaForm::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn SchemaForm::to_repr(SchemaForm) -> Reprpub(all) struct SchemaNodeInfo {
path : JsonPointer
form : String
shape : String
nullable : Bool
child_count : Int
} derive(Eq, Debug)#deprecated("`SchemaNodeInfo::equal` is deprecated, use `Eq::equal` instead.")
fn SchemaNodeInfo::equal(SchemaNodeInfo, SchemaNodeInfo) -> Bool#deprecated("`SchemaNodeInfo::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn SchemaNodeInfo::not_equal(x : SchemaNodeInfo, y : SchemaNodeInfo) -> Bool#deprecated("`SchemaNodeInfo::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn SchemaNodeInfo::to_repr(SchemaNodeInfo) -> Reprpub(all) struct SchemaStats {
node_count : Int
max_depth : Int
definition_count : Int
reference_count : Int
nullable_count : Int
empty_count : Int
type_count : Int
enum_count : Int
elements_count : Int
properties_count : Int
values_count : Int
discriminator_count : Int
required_property_count : Int
optional_property_count : Int
discriminator_branch_count : Int
} derive(Eq, Debug)#deprecated("`SchemaStats::equal` is deprecated, use `Eq::equal` instead.")
fn SchemaStats::equal(SchemaStats, SchemaStats) -> Bool#deprecated("`SchemaStats::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn SchemaStats::not_equal(x : SchemaStats, y : SchemaStats) -> Bool#deprecated("`SchemaStats::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn SchemaStats::to_repr(SchemaStats) -> Repr#deprecated("`ValidatedJson::equal` is deprecated, use `Eq::equal` instead.")
fn ValidatedJson::equal(ValidatedJson, ValidatedJson) -> Bool#deprecated("`ValidatedJson::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn ValidatedJson::not_equal(x : ValidatedJson, y : ValidatedJson) -> Bool#deprecated("`ValidatedJson::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn ValidatedJson::to_repr(ValidatedJson) -> Repr#deprecated("`ValidationOptions::equal` is deprecated, use `Eq::equal` instead.")
fn ValidationOptions::equal(ValidationOptions, ValidationOptions) -> Boolfn ValidationOptions::new(max_errors? : Int, max_depth? : Int, max_ref_depth? : Int, max_nodes? : Int) -> ValidationOptions#deprecated("`ValidationOptions::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn ValidationOptions::not_equal(x : ValidationOptions, y : ValidationOptions) -> Bool#deprecated("`ValidationOptions::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn ValidationOptions::to_repr(ValidationOptions) -> Reprpub(all) struct ValidationReport {
errors : Array[Diagnostic]
visited_nodes : Int
truncated : Bool
} derive(Debug)#deprecated("`ValidationReport::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn ValidationReport::to_repr(ValidationReport) -> Reprfn codec_from_schema(schema_text : StringView, options? : ValidationOptions) -> Result[JtdCodec, CodecError]fn generate_moonbit_types(document : SchemaDocument, root_name? : String) -> Result[String, CodegenError]fn generate_moonbit_types_with(document : SchemaDocument, options : CodegenOptions) -> Result[String, CodegenError]fn is_rfc3339_timestamp(text : String) -> Boolfn moon_field_name(name : String) -> Stringfn moon_type_name(name : String) -> Stringfn validate_json_text(document : SchemaDocument, text : StringView) -> Result[Array[Diagnostic], Diagnostic]fn validate_with(document : SchemaDocument, value : Json, options : ValidationOptions) -> ValidationReportfn version_banner() -> StringInstall
Download zipMoonBit-native RFC 8927 JSON Type Definition validator and code generator