{"id":25974334,"url":"https://github.com/fsprojects/fsharp.data.jsonschema","last_synced_at":"2026-02-10T07:11:23.501Z","repository":{"id":65382495,"uuid":"211152700","full_name":"fsprojects/FSharp.Data.JsonSchema","owner":"fsprojects","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-04T15:10:26.000Z","size":173,"stargazers_count":49,"open_issues_count":6,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-30T09:46:30.595Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fsprojects.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-09-26T18:10:01.000Z","updated_at":"2024-11-13T09:36:48.000Z","dependencies_parsed_at":"2023-12-29T18:03:47.169Z","dependency_job_id":"ea82e41f-dd05-4b71-9adc-7e8643f4eadb","html_url":"https://github.com/fsprojects/FSharp.Data.JsonSchema","commit_stats":null,"previous_names":["panesofglass/fsharp.data.jsonschema"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fsprojects%2FFSharp.Data.JsonSchema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fsprojects%2FFSharp.Data.JsonSchema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fsprojects%2FFSharp.Data.JsonSchema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fsprojects%2FFSharp.Data.JsonSchema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fsprojects","download_url":"https://codeload.github.com/fsprojects/FSharp.Data.JsonSchema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241951227,"owners_count":20047783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-05T02:22:56.327Z","updated_at":"2026-02-10T07:11:23.494Z","avatar_url":"https://github.com/fsprojects.png","language":"F#","readme":"# FSharp.Data.JsonSchema\n\nIdiomatic [JSON Schema](https://json-schema.org/) generation for F# types with a pluggable, target-agnostic Core IR. Translate F# types into JSON Schema, OpenAPI schemas, or implement your own custom translator.\n\n| Package | NuGet | Status |\n|---------|-------|--------|\n| FSharp.Data.JsonSchema.Core | [![NuGet](http://img.shields.io/nuget/v/FSharp.Data.JsonSchema.Core.svg?style=flat)](https://www.nuget.org/packages/FSharp.Data.JsonSchema.Core/) | ✅ Active |\n| FSharp.Data.JsonSchema.NJsonSchema | [![NuGet](http://img.shields.io/nuget/v/FSharp.Data.JsonSchema.NJsonSchema.svg?style=flat)](https://www.nuget.org/packages/FSharp.Data.JsonSchema.NJsonSchema/) | ✅ Active |\n| FSharp.Data.JsonSchema.OpenApi | [![NuGet](http://img.shields.io/nuget/v/FSharp.Data.JsonSchema.OpenApi.svg?style=flat)](https://www.nuget.org/packages/FSharp.Data.JsonSchema.OpenApi/) | ✅ Active |\n| FSharp.Data.JsonSchema | [![NuGet](http://img.shields.io/nuget/v/FSharp.Data.JsonSchema.svg?style=flat)](https://www.nuget.org/packages/FSharp.Data.JsonSchema/) | ⚠️ Deprecated (use NJsonSchema) |\n\n## Packages\n\n### FSharp.Data.JsonSchema.Core\n\nTarget-agnostic JSON Schema IR (intermediate representation) and F# type analyzer. Use this package when you want to analyze F# types into a schema document and translate to any target format.\n\n- `SchemaAnalyzer.analyze` recursively analyzes F# types into a `SchemaDocument`\n- `SchemaNode` discriminated union represents JSON Schema concepts (Object, Array, AnyOf, OneOf, Nullable, Primitive, Enum, Ref, Map, Const, Any)\n- `SchemaGeneratorConfig` controls discriminator name, naming policy, and additional properties\n- **No NJsonSchema or OpenAPI dependency** — only FSharp.Core and FSharp.SystemTextJson\n- Targets netstandard2.0 through net10.0\n\n### FSharp.Data.JsonSchema.NJsonSchema\n\nNJsonSchema-based JSON Schema generation for F# types (formerly `FSharp.Data.JsonSchema`).\n\n- `Generator.Create` and `Generator.CreateMemoized` generate `NJsonSchema.JsonSchema` from F# types\n- `Validation` module for validating JSON against a schema\n- `FSharp.Data.Json` serializer with schema validation\n- Targets netstandard2.0 through net10.0\n\n### FSharp.Data.JsonSchema ⚠️ DEPRECATED\n\n**This package is deprecated and renamed to `FSharp.Data.JsonSchema.NJsonSchema`.**\n\nThe `FSharp.Data.JsonSchema` package now serves as a compatibility shim that references `FSharp.Data.JsonSchema.NJsonSchema`. Please update your package reference to use `FSharp.Data.JsonSchema.NJsonSchema` directly. This deprecated package will not receive updates beyond version 3.0.0.\n\n### FSharp.Data.JsonSchema.OpenApi\n\nOpenAPI schema translator for F# types, designed for ASP.NET Core's built-in OpenAPI support.\n\n- `FSharpSchemaTransformer` implements `IOpenApiSchemaTransformer` for use with `MapOpenApi()`\n- Supports Microsoft.OpenApi 1.6.x (net9.0) and 2.0.x (net10.0)\n- Targets net9.0 and net10.0\n\n## Why This Library?\n\n[JSON Schema](https://json-schema.org/) is a standard format for describing JSON document structure, used extensively in [OpenAPI](https://www.openapis.org/), API documentation, and client-side validation.\n\n**F#-First Type Analysis:** This library provides idiomatic JSON Schema generation that understands F# types natively:\n- Discriminated unions → `anyOf` with discriminators\n- Options → nullable wrappers\n- Records → typed objects with required fields\n- Fieldless DUs → string enums\n\n**Pluggable Architecture:** Built around a target-agnostic Core IR:\n- **FSharp.Data.JsonSchema.Core** — Type analyzer that produces `SchemaNode` IR\n- **Translators** — Convert IR to any target format (NJsonSchema, OpenAPI, or custom)\n- **Extensible** — Implement your own translator for any schema format\n\n**Multiple Targets:** Out-of-the-box support for:\n- [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) — Full JSON Schema generation and validation\n- OpenAPI — Native ASP.NET Core integration via `IOpenApiSchemaTransformer`\n- Custom — Build your own translator over the Core IR\n\nWhile [FSharp.SystemTextJson](https://github.com/Tarmil/FSharp.SystemTextJson) handles JSON serialization beautifully, this library provides the schema definitions that document and validate that JSON.\n\n## Usage\n\n### Core: Analyze F# types into schema IR\n\n```fsharp\nopen FSharp.Data.JsonSchema.Core\n\ntype Person = { FirstName: string; LastName: string; Age: int option }\n\ntype Shape =\n    | Circle of radius: float\n    | Rectangle of width: float * height: float\n\n// Analyze a type into a SchemaDocument\nlet doc = SchemaAnalyzer.analyze SchemaGeneratorConfig.defaults typeof\u003cPerson\u003e\n\n// Pattern match over the schema IR\nmatch doc.Root with\n| SchemaNode.Object obj -\u003e\n    printfn \"Properties: %A\" (obj.Properties |\u003e List.map _.Name)\n    printfn \"Required: %A\" obj.Required\n| _ -\u003e ()\n```\n\n### NJsonSchema: Generate and validate JSON Schema\n\n```fsharp\n#r \"nuget: FSharp.Data.JsonSchema.NJsonSchema, 3.0.0\"\n#r \"nuget: NJsonSchema, 11.0.0\"\n\nopen FSharp.Data.JsonSchema\nopen FSharp.Data.JsonSchema.Validation\nopen NJsonSchema\n\n// Generate a JSON Schema from an F# type\nlet schema : JsonSchema = Generator.Create\u003cPerson\u003e()\n\n// Validate JSON against a schema\nlet json = \"\"\"{\"firstName\": \"John\", \"lastName\": \"Doe\"}\"\"\"\nlet result = Validation.validate schema json\n```\n\n### OpenAPI: ASP.NET Core integration\n\n```fsharp\n// In your ASP.NET Core application (Program.fs)\nopen FSharp.Data.JsonSchema.OpenApi\n\nbuilder.Services.AddOpenApi(fun options -\u003e\n    options.AddSchemaTransformer\u003cFSharpSchemaTransformer\u003e()\n)\n\n// Or with custom configuration:\nopen FSharp.Data.JsonSchema.Core\n\nlet config = { SchemaGeneratorConfig.defaults with DiscriminatorPropertyName = \"type\" }\nbuilder.Services.AddOpenApi(fun options -\u003e\n    options.AddSchemaTransformer(FSharpSchemaTransformer(config))\n)\n```\n\n## Supported Types\n\n| F# Type | Schema Representation |\n|---------|----------------------|\n| Records | `object` with properties and required |\n| Struct records | `object` (same as records) |\n| Multi-case DUs | `anyOf` with discriminator |\n| Fieldless DUs | `string` enum |\n| F# enums | `integer` enum |\n| `option\u003c'T\u003e` / `voption\u003c'T\u003e` | nullable wrapper |\n| `Nullable\u003c'T\u003e` | nullable wrapper |\n| `list\u003c'T\u003e` / `'T[]` / `seq\u003c'T\u003e` | `array` with items |\n| `Map\u003cstring, 'T\u003e` | `object` with additionalProperties |\n| Recursive types | `$ref` with definitions |\n| Generic types | Distinct schema per instantiation |\n| .NET classes | `object` via reflection |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffsprojects%2Ffsharp.data.jsonschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffsprojects%2Ffsharp.data.jsonschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffsprojects%2Ffsharp.data.jsonschema/lists"}