moonjtd

    MoonBit-native RFC 8927 JSON Type Definition validator and code generator

    json
    jtd
    rfc8927
    validation
    codegen
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    19 hours ago
    Downloads
    2

    #MoonJTD

    CI License

    MoonJTD is a MoonBit-native implementation of JSON Type Definition (JTD), as specified by RFC 8927. It validates schemas and JSON instances, emits standard instancePath / schemaPath diagnostics, and generates idiomatic MoonBit types and a schema-bound JSON codec API.

    #Why JTD

    JTD is intentionally smaller than JSON Schema. Its eight mutually exclusive forms map predictably to mainstream type systems, including records, enums, arrays, dictionaries, nullable values, references, and tagged unions. This makes it useful for API contracts and source generation where deterministic types matter more than arbitrary validation constraints.

    #Project status

    The MVP contains the complete eight-form JTD data model, strict schema checks, bounded validation, MoonBit type generation, a validated JSON codec API, a builder API, schema analysis, machine-readable reports, a CLI, runnable examples, and multi-target CI. The hash-pinned upstream conformance corpus currently passes all 316 validation cases and all 49 invalid-schema cases.

    JTD is an Experimental RFC rather than an IETF Standards Track specification. MoonJTD states that status explicitly and targets the published RFC semantics.

    #Scope

    MoonJTD implements RFC 8927. It is not a JSON Schema validator, an Apache Avro codec, a database migration system, or a general-purpose data-contract platform.

    #Current release status

    MoonJTD 0.1.1 is published on Mooncakes. Install the package with:

    moon add ppyj663/moonjtd@0.1.1

    To evaluate the source, CLI, and examples directly from GitHub:

    git clone https://github.com/ppyj663/MoonJTD.git cd MoonJTD moon test --target js moon run examples/quickstart --target js

    The Git repository remains the authoritative source for development.

    #Library example

    let 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()) }
    }

    The typed builder avoids raw schema JSON:

    ///|
    let user = @jtd.jtd_object()
    .required("id", @jtd.jtd_uint32())
    .required("name", @jtd.jtd_string())
    .optional("email", @jtd.jtd_string())
    .build()

    Run the examples:

    moon run examples/quickstart --target js moon run examples/codegen --target js

    #CLI

    moonjtd --help moonjtd check schema.jtd.json moonjtd validate schema.jtd.json instance.json moonjtd generate schema.jtd.json RootType output.mbt moonjtd inspect schema.jtd.json moonjtd format schema.jtd.json output.json

    During development, replace moonjtd with moon run cmd/main --target js --.

    Exit status is 0 for success, 1 for an invalid schema/instance or failed generation, and 2 for usage or filesystem errors. Malformed JSON is an input error (1); a missing or unreadable file is a filesystem error (2).

    #Repository structure

    MoonJTD/ ├── *.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 integration

    Generated pkg.generated.mbti interface files are committed so reviewers can inspect the public API. Build output, downloaded conformance data, and Mooncakes working state are ignored.

    #Validation safety

    ValidationOptions bounds the number of diagnostics, instance depth, reference depth, and visited nodes. SchemaCheckOptions independently bounds untrusted schema traversal. Recursive references therefore fail closed instead of overflowing the runtime stack indefinitely.

    #Testing

    moon 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

    Native tests require a C compiler (clang, gcc, cc, or MSVC cl). Native static checking does not require one.

    The conformance script downloads two data files from a fixed upstream commit, checks their SHA-256 digests, and keeps them under ignored _build/ storage. The files are not redistributed by MoonJTD because their upstream repository does not declare a license. See the conformance notes for the exact revision, hashes, runner behavior, and reproducibility details.

    #Standards and provenance

    • RFC 8927, JSON Type Definition, November 2020.
    • RFC 6901 JSON Pointer paths for validation diagnostics.
    • RFC 3339 timestamps as refined by RFC 8927.

    See third-party notices for source and AI-assistance disclosure, development history for the feature and commit trail, and reproducibility for the validated toolchain. No source code from another JTD implementation is copied into this repository.

    #License

    Apache-2.0. See LICENSE and THIRD_PARTY_NOTICES.md.

    CodecError

    pub(all) suberror CodecError {
    CodecInvalidSchema(Array[Diagnostic])
    CodecInvalidJson(String)
    CodecValidationFailed(Array[Diagnostic])
    } derive(Eq,
    Debug
    )

    CodegenError

    pub(all) suberror CodegenError {
    CodegenDiagnostic(Diagnostic)
    } derive(Eq,
    Debug
    )

    SchemaError

    pub(all) suberror SchemaError {
    SchemaDiagnostic(Diagnostic)
    } derive(Eq,
    Debug
    )

    CodegenOptions

    pub(all) struct CodegenOptions {
    root_name : String
    public_types : Bool
    derive_eq : Bool
    derive_debug : Bool
    header : Bool
    } derive(Eq,
    Debug
    )

    Controls naming and visibility of generated MoonBit declarations.

    CodegenOptions::default

    CodegenOptions::new

    fn CodegenOptions::new(root_name? : String, public_types? : Bool, derive_eq? : Bool, derive_debug? : Bool, header? : Bool) -> CodegenOptions

    CodegenOptions::root_name

    fn CodegenOptions::root_name(self : CodegenOptions) -> String

    Diagnostic

    pub(all) struct Diagnostic {
    code : DiagnosticCode
    message : String
    instance_path : JsonPointer
    schema_path : JsonPointer
    } derive(Eq,
    Debug
    )

    A structured error that can be rendered by a CLI or editor integration.

    Diagnostic::code

    Diagnostic::instance_path

    fn Diagnostic::instance_path(self : Diagnostic) -> JsonPointer

    Diagnostic::message

    fn Diagnostic::message(self : Diagnostic) -> String

    Diagnostic::new

    fn Diagnostic::new(code : DiagnosticCode, message : String, instance_path? : JsonPointer, schema_path? : JsonPointer) -> Diagnostic

    Diagnostic::schema_path

    fn Diagnostic::schema_path(self : Diagnostic) -> JsonPointer

    Diagnostic::to_string

    fn Diagnostic::to_string(self : Diagnostic) -> String

    DiagnosticCode

    pub(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
    )

    Stable categories for machine-readable MoonJTD diagnostics.

    DiagnosticCode::name

    fn DiagnosticCode::name(self : DiagnosticCode) -> String

    DiscriminatorSchemaBuilder

    pub(all) struct DiscriminatorSchemaBuilder {
    tag : String
    mapping : Map[String, Schema]
    nullable : Bool
    metadata : Map[String, Json]
    } derive(
    Debug
    )

    Fluent builder for a JTD discriminator-form schema.

    DiscriminatorSchemaBuilder::branch

    DiscriminatorSchemaBuilder::branch_count

    DiscriminatorSchemaBuilder::build

    DiscriminatorSchemaBuilder::metadata_entry

    fn DiscriminatorSchemaBuilder::metadata_entry(self : DiscriminatorSchemaBuilder, name : String, value : Json) -> DiscriminatorSchemaBuilder

    DiscriminatorSchemaBuilder::new

    DiscriminatorSchemaBuilder::nullable

    DocumentBuilder

    pub(all) struct DocumentBuilder {
    root : Schema
    definitions : Map[String, Schema]
    } derive(
    Debug
    )

    Fluent builder for a complete schema document and its root definitions.

    DocumentBuilder::build

    DocumentBuilder::definition

    fn DocumentBuilder::definition(self : DocumentBuilder, name : String, schema : Schema) -> DocumentBuilder

    DocumentBuilder::definition_count

    fn DocumentBuilder::definition_count(self : DocumentBuilder) -> Int

    DocumentBuilder::new

    JsonPointer

    pub(all) struct JsonPointer {
    segments : Array[PathSegment]
    } derive(Eq,
    Debug
    )

    An immutable path into either a schema or an instance document.

    JsonPointer::append

    fn JsonPointer::append(self : JsonPointer, suffix : JsonPointer) -> JsonPointer

    JsonPointer::depth

    fn JsonPointer::depth(self : JsonPointer) -> Int

    JsonPointer::display

    fn JsonPointer::display(self : JsonPointer) -> String

    JsonPointer::index

    fn JsonPointer::index(self : JsonPointer, index : Int) -> JsonPointer

    JsonPointer::is_root

    fn JsonPointer::is_root(self : JsonPointer) -> Bool

    JsonPointer::last_index

    fn JsonPointer::last_index(self : JsonPointer) -> Int?

    JsonPointer::last_property

    fn JsonPointer::last_property(self : JsonPointer) -> String?

    JsonPointer::parent

    fn JsonPointer::parent(self : JsonPointer) -> JsonPointer?

    JsonPointer::property

    fn JsonPointer::property(self : JsonPointer, name : String) -> JsonPointer

    JsonPointer::root

    fn JsonPointer::root() -> JsonPointer

    JsonPointer::segments_copy

    fn JsonPointer::segments_copy(self : JsonPointer) -> Array[PathSegment]

    JsonPointer::to_string

    fn JsonPointer::to_string(self : JsonPointer) -> String

    JtdCodec

    pub(all) struct JtdCodec {
    document : SchemaDocument
    options : ValidationOptions
    } derive(
    Debug
    )

    Schema-bound JSON codec with the same resource limits as direct validation.

    JtdCodec::decode

    fn JtdCodec::decode(self : JtdCodec, text : StringView) -> Result[ValidatedJson, CodecError]

    Parse JSON text, validate it, and return only a schema-conforming value.

    JtdCodec::decode_batch

    fn JtdCodec::decode_batch(self : JtdCodec, values : Array[Json]) -> Array[Result[ValidatedJson, CodecError]]

    Decode multiple independent JSON values, preserving input order.

    JtdCodec::decode_json

    fn JtdCodec::decode_json(self : JtdCodec, value : Json) -> Result[ValidatedJson, CodecError]

    Validate an already parsed JSON value and wrap it on success.

    JtdCodec::decode_json_array

    fn JtdCodec::decode_json_array(self : JtdCodec, text : StringView) -> Result[Array[ValidatedJson], CodecError]

    Decode a JSON array and validate each element as a separate root instance.

    JtdCodec::document

    fn JtdCodec::document(self : JtdCodec) -> SchemaDocument

    JtdCodec::encode_json

    fn JtdCodec::encode_json(self : JtdCodec, value : Json, escape_slash? : Bool) -> Result[String, CodecError]

    Validate a JSON value before serializing it.

    JtdCodec::encode_validated

    fn JtdCodec::encode_validated(self : JtdCodec, value : ValidatedJson, escape_slash? : Bool) -> String

    A previously validated value can be serialized without another traversal.

    JtdCodec::new

    fn JtdCodec::new(document : SchemaDocument, options? : ValidationOptions) -> Result[JtdCodec, CodecError]

    JtdCodec::options

    fn JtdCodec::options(self : JtdCodec) -> ValidationOptions

    JtdType

    pub(all) enum JtdType {
    BooleanType
    Float32Type
    Float64Type
    Int8Type
    Uint8Type
    Int16Type
    Uint16Type
    Int32Type
    Uint32Type
    StringType
    TimestampType
    } derive(Eq,
    Debug
    )

    Primitive types defined by RFC 8927 section 2.2.3.

    JtdType::is_integer

    fn JtdType::is_integer(self : JtdType) -> Bool

    JtdType::is_numeric

    fn JtdType::is_numeric(self : JtdType) -> Bool

    JtdType::is_signed

    fn JtdType::is_signed(self : JtdType) -> Bool

    JtdType::maximum

    fn JtdType::maximum(self : JtdType) -> Double?

    JtdType::minimum

    fn JtdType::minimum(self : JtdType) -> Double?

    JtdType::name

    fn JtdType::name(self : JtdType) -> String

    ObjectSchemaBuilder

    pub(all) struct ObjectSchemaBuilder {
    required : Map[String, Schema]
    optional : Map[String, Schema]
    additional : Bool
    nullable : Bool
    metadata : Map[String, Json]
    } derive(
    Debug
    )

    Fluent builder for a JTD properties-form schema.

    ObjectSchemaBuilder::allow_additional

    fn ObjectSchemaBuilder::allow_additional(self : ObjectSchemaBuilder, allowed : Bool) -> ObjectSchemaBuilder

    ObjectSchemaBuilder::build

    ObjectSchemaBuilder::metadata_entry

    fn ObjectSchemaBuilder::metadata_entry(self : ObjectSchemaBuilder, name : String, value : Json) -> ObjectSchemaBuilder

    ObjectSchemaBuilder::new

    ObjectSchemaBuilder::nullable

    fn ObjectSchemaBuilder::nullable(self : ObjectSchemaBuilder, nullable : Bool) -> ObjectSchemaBuilder

    ObjectSchemaBuilder::optional

    fn ObjectSchemaBuilder::optional(self : ObjectSchemaBuilder, name : String, schema : Schema) -> ObjectSchemaBuilder

    ObjectSchemaBuilder::optional_count

    fn ObjectSchemaBuilder::optional_count(self : ObjectSchemaBuilder) -> Int

    ObjectSchemaBuilder::required

    fn ObjectSchemaBuilder::required(self : ObjectSchemaBuilder, name : String, schema : Schema) -> ObjectSchemaBuilder

    ObjectSchemaBuilder::required_count

    fn ObjectSchemaBuilder::required_count(self : ObjectSchemaBuilder) -> Int

    PathSegment

    pub(all) enum PathSegment {
    Property(String)
    Index(Int)
    } derive(Eq,
    Debug
    )

    One segment in an RFC 6901 JSON Pointer.

    Schema

    pub(all) struct Schema {
    form : SchemaForm
    nullable : Bool
    metadata : Map[String, Json]
    } derive(
    Debug
    )

    A schema node. Metadata is retained without assigning it validation meaning.

    Schema::allows_additional_properties

    fn Schema::allows_additional_properties(self : Schema) -> Bool

    Schema::discriminator

    fn Schema::discriminator(tag : String, mapping : Map[String, Schema]) -> Schema

    Schema::discriminator_mapping

    fn Schema::discriminator_mapping(self : Schema) -> Map[String, Schema]?

    Schema::discriminator_tag

    fn Schema::discriminator_tag(self : Schema) -> String?

    Schema::element_schema

    fn Schema::element_schema(self : Schema) -> Schema?

    Schema::elements

    fn Schema::elements(element : Schema) -> Schema

    Schema::empty

    fn Schema::empty() -> Schema

    Schema::enum_

    fn Schema::enum_(values : Array[String]) -> Schema

    Schema::enum_values

    fn Schema::enum_values(self : Schema) -> Array[String]?

    Schema::form

    fn Schema::form(self : Schema) -> SchemaForm

    Schema::form_name

    fn Schema::form_name(self : Schema) -> String

    Schema::is_nullable

    fn Schema::is_nullable(self : Schema) -> Bool

    Schema::metadata

    fn Schema::metadata(self : Schema) -> Map[String, Json]

    Schema::new

    fn Schema::new(form : SchemaForm) -> Schema

    Schema::optional_properties

    fn Schema::optional_properties(self : Schema) -> Map[String, Schema]?

    Schema::properties

    fn Schema::properties(required : Map[String, Schema], optional : Map[String, Schema], additional : Bool) -> Schema

    Schema::ref_name

    fn Schema::ref_name(self : Schema) -> String?

    Schema::reference

    fn Schema::reference(name : String) -> Schema

    Schema::required_properties

    fn Schema::required_properties(self : Schema) -> Map[String, Schema]?

    Schema::type_

    fn Schema::type_(kind : JtdType) -> Schema

    Schema::type_kind

    fn Schema::type_kind(self : Schema) -> JtdType?

    Schema::value_schema

    fn Schema::value_schema(self : Schema) -> Schema?

    Schema::values

    fn Schema::values(value : Schema) -> Schema

    Schema::with_metadata

    fn Schema::with_metadata(self : Schema, metadata : Map[String, Json]) -> Schema

    Schema::with_nullable

    fn Schema::with_nullable(self : Schema, nullable : Bool) -> Schema

    SchemaCheckOptions

    pub(all) struct SchemaCheckOptions {
    max_depth : Int
    max_nodes : Int
    max_errors : Int
    } derive(Eq,
    Debug
    )

    Limits applied while checking an untrusted schema document.

    SchemaCheckOptions::default

    SchemaCheckOptions::max_depth

    fn SchemaCheckOptions::max_depth(self : SchemaCheckOptions) -> Int

    SchemaCheckOptions::max_errors

    fn SchemaCheckOptions::max_errors(self : SchemaCheckOptions) -> Int

    SchemaCheckOptions::max_nodes

    fn SchemaCheckOptions::max_nodes(self : SchemaCheckOptions) -> Int

    SchemaCheckOptions::new

    fn SchemaCheckOptions::new(max_depth? : Int, max_nodes? : Int, max_errors? : Int) -> SchemaCheckOptions

    SchemaDocument

    pub(all) struct SchemaDocument {
    root : Schema
    definitions : Map[String, Schema]
    } derive(
    Debug
    )

    A complete JTD document. Only this root level may contain definitions.

    SchemaDocument::definition

    fn SchemaDocument::definition(self : SchemaDocument, name : String) -> Schema?

    SchemaDocument::definition_count

    fn SchemaDocument::definition_count(self : SchemaDocument) -> Int

    SchemaDocument::definition_names

    fn SchemaDocument::definition_names(self : SchemaDocument) -> Array[String]

    SchemaDocument::definitions

    fn SchemaDocument::definitions(self : SchemaDocument) -> Map[String, Schema]

    SchemaDocument::has_definition

    fn SchemaDocument::has_definition(self : SchemaDocument, name : String) -> Bool

    SchemaDocument::new

    fn SchemaDocument::new(root : Schema, definitions? : Map[String, Schema]) -> SchemaDocument

    SchemaDocument::root

    SchemaForm

    pub(all) enum SchemaForm {
    EmptyForm
    RefForm(String)
    TypeForm(JtdType)
    EnumForm(Array[String])
    ElementsForm(Schema)
    PropertiesForm(Map[String, Schema], Map[String, Schema], Bool)
    ValuesForm(Schema)
    DiscriminatorForm(String, Map[String, Schema])
    } derive(
    Debug
    )

    The eight mutually exclusive schema forms from RFC 8927.

    SchemaNodeInfo

    pub(all) struct SchemaNodeInfo {
    path : JsonPointer
    form : String
    shape : String
    nullable : Bool
    child_count : Int
    } derive(Eq,
    Debug
    )

    One syntactic node in a schema inventory.

    SchemaNodeInfo::child_count

    fn SchemaNodeInfo::child_count(self : SchemaNodeInfo) -> Int

    SchemaNodeInfo::form

    fn SchemaNodeInfo::form(self : SchemaNodeInfo) -> String

    SchemaNodeInfo::is_nullable

    fn SchemaNodeInfo::is_nullable(self : SchemaNodeInfo) -> Bool

    SchemaNodeInfo::path

    SchemaNodeInfo::shape

    fn SchemaNodeInfo::shape(self : SchemaNodeInfo) -> String

    SchemaStats

    pub(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
    )

    Structural metrics for a complete JTD schema document.

    SchemaStats::definition_count

    fn SchemaStats::definition_count(self : SchemaStats) -> Int

    SchemaStats::discriminator_branch_count

    fn SchemaStats::discriminator_branch_count(self : SchemaStats) -> Int

    SchemaStats::discriminator_count

    fn SchemaStats::discriminator_count(self : SchemaStats) -> Int

    SchemaStats::elements_count

    fn SchemaStats::elements_count(self : SchemaStats) -> Int

    SchemaStats::empty_count

    fn SchemaStats::empty_count(self : SchemaStats) -> Int

    SchemaStats::enum_count

    fn SchemaStats::enum_count(self : SchemaStats) -> Int

    SchemaStats::max_depth

    fn SchemaStats::max_depth(self : SchemaStats) -> Int

    SchemaStats::node_count

    fn SchemaStats::node_count(self : SchemaStats) -> Int

    SchemaStats::nullable_count

    fn SchemaStats::nullable_count(self : SchemaStats) -> Int

    SchemaStats::optional_property_count

    fn SchemaStats::optional_property_count(self : SchemaStats) -> Int

    SchemaStats::properties_count

    fn SchemaStats::properties_count(self : SchemaStats) -> Int

    SchemaStats::reference_count

    fn SchemaStats::reference_count(self : SchemaStats) -> Int

    SchemaStats::required_property_count

    fn SchemaStats::required_property_count(self : SchemaStats) -> Int

    SchemaStats::to_string

    fn SchemaStats::to_string(self : SchemaStats) -> String

    SchemaStats::type_count

    fn SchemaStats::type_count(self : SchemaStats) -> Int

    SchemaStats::values_count

    fn SchemaStats::values_count(self : SchemaStats) -> Int

    ValidatedJson

    pub(all) struct ValidatedJson {
    value : Json
    } derive(Eq,
    Debug
    )

    A JSON value proven valid against the codec's JTD document at decode time.

    ValidatedJson::stringify

    fn ValidatedJson::stringify(self : ValidatedJson, escape_slash? : Bool) -> String

    ValidatedJson::value

    fn ValidatedJson::value(self : ValidatedJson) -> Json

    ValidationOptions

    pub(all) struct ValidationOptions {
    max_errors : Int
    max_depth : Int
    max_ref_depth : Int
    max_nodes : Int
    } derive(Eq,
    Debug
    )

    Resource limits for validating untrusted JSON values and recursive schemas.

    ValidationOptions::default

    ValidationOptions::max_depth

    fn ValidationOptions::max_depth(self : ValidationOptions) -> Int

    ValidationOptions::max_errors

    fn ValidationOptions::max_errors(self : ValidationOptions) -> Int

    ValidationOptions::max_nodes

    fn ValidationOptions::max_nodes(self : ValidationOptions) -> Int

    ValidationOptions::max_ref_depth

    fn ValidationOptions::max_ref_depth(self : ValidationOptions) -> Int

    ValidationOptions::new

    fn ValidationOptions::new(max_errors? : Int, max_depth? : Int, max_ref_depth? : Int, max_nodes? : Int) -> ValidationOptions

    ValidationReport

    pub(all) struct ValidationReport {
    errors : Array[Diagnostic]
    visited_nodes : Int
    truncated : Bool
    } derive(
    Debug
    )

    Complete outcome of one validation pass.

    ValidationReport::errors

    ValidationReport::is_truncated

    fn ValidationReport::is_truncated(self : ValidationReport) -> Bool

    ValidationReport::is_valid

    fn ValidationReport::is_valid(self : ValidationReport) -> Bool

    ValidationReport::visited_nodes

    fn ValidationReport::visited_nodes(self : ValidationReport) -> Int

    SPECIFICATION

    let SPECIFICATION : String

    The RFC implemented by this package.

    VERSION

    let VERSION : String

    Semantic version of the public MoonJTD API.

    analyze_schema

    fn analyze_schema(document : SchemaDocument) -> SchemaStats

    Count schema structure without following references, so recursive definitions are safe and each syntactic node is counted exactly once.

    check_schema

    fn check_schema(document : SchemaDocument) -> Array[Diagnostic]

    check_schema_with

    fn check_schema_with(document : SchemaDocument, options : SchemaCheckOptions) -> Array[Diagnostic]

    Check cross-node constraints that cannot be decided while parsing one node.

    codec_error_diagnostics

    fn codec_error_diagnostics(error : CodecError) -> Array[Diagnostic]

    codec_error_message

    fn codec_error_message(error : CodecError) -> String

    codec_from_schema

    fn codec_from_schema(schema_text : StringView, options? : ValidationOptions) -> Result[JtdCodec, CodecError]

    diagnostic_to_json

    fn diagnostic_to_json(diagnostic : Diagnostic) -> Json

    diagnostics_to_json

    fn diagnostics_to_json(diagnostics : Array[Diagnostic]) -> Json

    diagnostics_to_string

    fn diagnostics_to_string(diagnostics : Array[Diagnostic], pretty? : Bool) -> String

    generate_moonbit_types

    fn generate_moonbit_types(document : SchemaDocument, root_name? : String) -> Result[String, CodegenError]

    generate_moonbit_types_with

    fn generate_moonbit_types_with(document : SchemaDocument, options : CodegenOptions) -> Result[String, CodegenError]

    Generate deterministic MoonBit type declarations for a checked JTD document.

    is_rfc3339_timestamp

    fn is_rfc3339_timestamp(text : String) -> Bool

    Validate the RFC 3339 profile required by RFC 8927 timestamp values.

    json_kind

    fn json_kind(value : Json) -> String

    jtd_any

    fn jtd_any() -> Schema

    Short constructor functions for schema-builder DSLs.

    jtd_array

    fn jtd_array(element : Schema) -> Schema

    jtd_boolean

    fn jtd_boolean() -> Schema

    jtd_document

    fn jtd_document(root : Schema) -> DocumentBuilder

    jtd_enum

    fn jtd_enum(values : Array[String]) -> Schema

    jtd_float32

    fn jtd_float32() -> Schema

    jtd_float64

    fn jtd_float64() -> Schema

    jtd_int16

    fn jtd_int16() -> Schema

    jtd_int32

    fn jtd_int32() -> Schema

    jtd_int8

    fn jtd_int8() -> Schema

    jtd_map

    fn jtd_map(value : Schema) -> Schema

    jtd_object

    fn jtd_object() -> ObjectSchemaBuilder

    jtd_reference

    fn jtd_reference(name : String) -> Schema

    jtd_string

    fn jtd_string() -> Schema

    jtd_timestamp

    fn jtd_timestamp() -> Schema

    jtd_type_from_name

    fn jtd_type_from_name(name : String) -> JtdType?

    jtd_uint16

    fn jtd_uint16() -> Schema

    jtd_uint32

    fn jtd_uint32() -> Schema

    jtd_uint8

    fn jtd_uint8() -> Schema

    jtd_union

    fn jtd_union(tag : String) -> DiscriminatorSchemaBuilder

    lint_schema

    fn lint_schema(document : SchemaDocument) -> Array[Diagnostic]

    Produce human-readable lint diagnostics that are not RFC correctness errors.

    moon_field_name

    fn moon_field_name(name : String) -> String

    Convert an arbitrary property name to a safe MoonBit field identifier.

    moon_type_name

    fn moon_type_name(name : String) -> String

    Convert an arbitrary schema name to a valid exported MoonBit type name.

    parse_checked_schema

    fn parse_checked_schema(text : StringView) -> Result[SchemaDocument, Array[Diagnostic]]

    Parse a schema and reject semantic violations in one operation.

    parse_schema

    fn parse_schema(text : StringView) -> Result[SchemaDocument, SchemaError]

    Parse UTF-8 JSON text as a complete RFC 8927 schema document.

    parse_schema_json

    fn parse_schema_json(value : Json) -> Result[SchemaDocument, SchemaError]

    Parse a JSON value as a complete RFC 8927 schema document.

    referenced_definitions

    fn referenced_definitions(document : SchemaDocument) -> Array[String]

    Collect every syntactically referenced definition name.

    rfc3339_day

    fn rfc3339_day(text : String) -> Int?

    rfc3339_hour

    fn rfc3339_hour(text : String) -> Int?

    rfc3339_minute

    fn rfc3339_minute(text : String) -> Int?

    rfc3339_month

    fn rfc3339_month(text : String) -> Int?

    rfc3339_second

    fn rfc3339_second(text : String) -> Int?

    rfc3339_year

    fn rfc3339_year(text : String) -> Int?

    scalar_accepts

    fn scalar_accepts(kind : JtdType, value : Json) -> Bool

    scalar_expectation

    fn scalar_expectation(kind : JtdType) -> String

    schema_inventory

    fn schema_inventory(document : SchemaDocument) -> Array[SchemaNodeInfo]

    Enumerate each syntactic schema node without following refs.

    schema_node_info_to_json

    fn schema_node_info_to_json(info : SchemaNodeInfo) -> Json

    schema_report_json

    fn schema_report_json(document : SchemaDocument) -> Json

    schema_report_markdown

    fn schema_report_markdown(document : SchemaDocument) -> String

    schema_report_string

    fn schema_report_string(document : SchemaDocument, pretty? : Bool) -> String

    schema_shape

    fn schema_shape(schema : Schema) -> String

    Return a deep structural form signature useful in reports and tests.

    schema_stats_to_json

    fn schema_stats_to_json(stats : SchemaStats) -> Json

    schema_to_json

    fn schema_to_json(document : SchemaDocument) -> Json

    Convert a schema document into its JSON data model.

    schema_to_pretty_string

    fn schema_to_pretty_string(document : SchemaDocument, indent? : Int) -> String

    Render indented JSON without depending on host filesystem or console APIs.

    schema_to_string

    fn schema_to_string(document : SchemaDocument) -> String

    Serialize a schema document as compact JSON.

    unused_definitions

    fn unused_definitions(document : SchemaDocument) -> Array[String]

    Definitions that are not transitively reachable from the root schema.

    validate

    fn validate(document : SchemaDocument, value : Json) -> Array[Diagnostic]

    validate_json_text

    fn validate_json_text(document : SchemaDocument, text : StringView) -> Result[Array[Diagnostic], Diagnostic]

    validate_with

    fn validate_with(document : SchemaDocument, value : Json, options : ValidationOptions) -> ValidationReport

    validation_report_to_json

    fn validation_report_to_json(report : ValidationReport) -> Json

    version_banner

    fn version_banner() -> String

    Return a compact identity suitable for CLI version output.