{"id":26478691,"url":"https://github.com/fsprojects/FSharp.Data.JsonSchema","last_synced_at":"2025-03-20T01:16:59.297Z","repository":{"id":65382495,"uuid":"211152700","full_name":"fsprojects/FSharp.Data.JsonSchema","owner":"fsprojects","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-16T16:49:53.000Z","size":173,"stargazers_count":51,"open_issues_count":3,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-16T17:33:14.226Z","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-26T18:10:01.000Z","updated_at":"2025-03-16T16:50:13.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":244531018,"owners_count":20467392,"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-20T01:16:57.835Z","updated_at":"2025-03-20T01:16:59.287Z","avatar_url":"https://github.com/fsprojects.png","language":"F#","readme":"# FSharp.Data.JsonSchema\n\nProvides an opinionated, idiomatic JSON serializer and [JSON Schema](https://json-schema.org/) definition generation for F# types using [FSharp.SystemTextJson](https://github.com/Tarmil/FSharp.SystemTextJson) and [NJsonSchema](https://github.com/RicoSuter/NJsonSchema).\n\n[![NuGet Status](http://img.shields.io/nuget/v/FSharp.Data.JsonSchema.svg?style=flat)](https://www.nuget.org/packages/FSharp.Data.JsonSchema/)\n![Build status](https://github.com/panesofglass/FSharp.Data.JsonSchema/workflows/CI/badge.svg)\n\n## Why JSON Schema?\n\n[JSON Schema](https://json-schema.org/) is a standard, evolving format for specifying the structure of JSON documents. JSON Schema is used in [Open API](https://www.openapis.org/) and can be used by clients to validate that the payload received or to be sent matches the expected schema. Use of these documents can allow for a more nuanced approach to versioning APIs, as well.\n\nTools exist for generating nicely formatted JSON from F#, e.g. [FSharpLu.Json](https://github.com/Microsoft/fsharplu), [Newtonsoft.Json.FSharp](https://github.com/haf/Newtonsoft.Json.FSharp), [Newtonsoft.Json.FSharp.Idiomatic](https://github.com/baronfel/Newtonsoft.Json.FSharp.Idiomatic), and [FSharp.SystemTextJson](https://github.com/Tarmil/FSharp.SystemTextJson).\n\n[Newtonsoft.Json Schema](https://www.newtonsoft.com/jsonschema) and [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) provide a way to generate and validate JSON Schema for .NET languages, but these don't necessarily translate well to F# types, e.g. `anyOf` mapping to F#'s discriminated unions. This library strives to fill this gap.\n\n## Usage\n\nBelow is a simple example on how to deserialize a JSON string into a F# record type using a json schema to validate the structure of the data:\n\n```fsharp\n#r \"nuget: FSharp.Data.JsonSchema, 2.0.2\"\n#r \"nuget: NJsonSchema, 11.0.0\"\n\nopen FSharp.Data.JsonSchema\nopen FSharp.Data.JsonSchema.Validation\nopen NJsonSchema\n\nlet personJson = \"\"\"\n{\n    \"id\": 7,\n    \"name\": \"John Doe\",\n    \"age\": 22,\n    \"hobbies\": {\n        \"indoor\": [\n            \"Chess\"\n        ],\n        \"outdoor\": [\n            \"Basketball\",\n            \"Stand-up Comedy\"\n        ]\n    }\n}\n\"\"\"\n\nlet personJsonSchema = \"\"\"\n{\n    \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n    \"$id\": \"https://example.com/employee.schema.json\",\n    \"title\": \"Record of employee\",\n    \"description\": \"This document records the details of an employee\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"id\": {\n            \"description\": \"A unique identifier for an employee\",\n            \"type\": \"number\"\n        },\n        \"name\": {\n            \"description\": \"Full name of the employee\",\n            \"type\": \"string\"\n        },\n        \"age\": {\n            \"description\": \"Age of the employee\",\n            \"type\": \"number\"\n        },\n        \"hobbies\": {\n            \"description\": \"Hobbies of the employee\",\n            \"type\": \"object\",\n            \"properties\": {\n                \"indoor\": {\n                    \"type\": \"array\",\n                    \"items\": {\n                        \"description\": \"List of indoor hobbies\",\n                        \"type\": \"string\"\n                    }\n                },\n                \"outdoor\": {\n                    \"type\": \"array\",\n                    \"items\": {\n                        \"description\": \"List of outdoor hobbies\",\n                        \"type\": \"string\"\n                    }\n                }\n            }\n        }\n    }\n}\n\"\"\"\n\ntype Person = {\n    Id: int\n    Name: string\n    Age: int\n    Hobbies: {|\n        Indoor: string list\n        Outdoor: string list\n    |}\n}\n\nlet jsonSchema = JsonSchema.FromJsonAsync(personJsonSchema).Result\n\nlet result : Result\u003cunit, Validation.ValidationError array\u003e = Validation.validate jsonSchema personJson\n\nlet person : Result\u003cPerson, Validation.ValidationError array\u003e = FSharp.Data.Json.DeserializeWithValidation\u003cPerson\u003e(personJson, jsonSchema)\n```\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"}