Community.JsonSchema
v2.3.1JSON Schema validation and generation for Darklang types. Validate JSON payloads against schemas, generate schemas from type definitions, and compose complex validation rules.
dark pull Community.JsonSchema
Community.JsonSchema provides a comprehensive toolkit for working with JSON Schema in Darklang. Use it to validate incoming JSON payloads against schemas, automatically generate schemas from your Darklang type definitions, and compose schemas together for complex validation scenarios. Built on top of Community.JsonParser, it supports draft 2020-12 of the JSON Schema specification.
Getting Started
dark
let schema = Community.JsonSchema.fromType<MyRecord> let result = Community.JsonSchema.validate schema jsonString match result with | Ok validated -> // use validated data Stdlib.String.append "Valid: " (Stdlib.Json.serialize validated) | Error errors -> // handle validation errors errors |> Stdlib.List.map (fun e -> e.message) |> Stdlib.String.join ", "
Features
- Validate JSON strings against JSON Schema definitions
- Generate schemas automatically from Darklang record and enum types
- Compose multiple schemas with
allOf,anyOf, andoneOf - Support for nullable types and default values
- Parse and serialize schemas to and from JSON strings
- Detailed validation error messages with JSON pointer paths
- Compatible with JSON Schema draft 2020-12
validate (schema: Schema) (json: String) : Result<Json, List<ValidationError>>
Validates a JSON string against the given schema. Returns Ok with the parsed JSON if valid, or Error with a list of validation errors.
fromType<'a> : Schema
Generates a JSON Schema from a Darklang type definition. Works with records, enums, and primitive types.
toString (schema: Schema) : String
Serializes a Schema to its JSON string representation.
parse (schemaJson: String) : Result<Schema, String>
Parses a JSON Schema from a string. Returns Error if the schema is invalid.
compose (schemas: List<Schema>) : Schema
Composes multiple schemas using allOf. The resulting schema validates against all input schemas.
optional (schema: Schema) : Schema
Wraps a schema to allow null values in addition to the schema type.
withDefault (schema: Schema) (defaultValue: Json) : Schema
Adds a default value to a schema definition.
v2.3.1
Feb 24, 2026
Fix validation of nested nullable types
v2.3.0
Feb 10, 2026
Add compose and optional functions
v2.2.0
Jan 15, 2026
Schema generation from record types
v2.1.0
Dec 20, 2025
Add withDefault support
v2.0.0
Nov 1, 2025
Breaking: Restructured Schema type for composability
v1.0.0
Aug 15, 2025
Initial release
Dependencies
Community.JsonSchema
Darklang.Stdlib
Community.JsonParser
Used By
47 packages depend on Community.JsonSchema