Community.JsonSchema

v2.3.1

JSON Schema validation and generation for Darklang types. Validate JSON payloads against schemas, generate schemas from type definitions, and compose complex validation rules.

by Community | MIT | Published 5 hours ago | 23 functions | 8 types
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, and oneOf
  • 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