{"id":21143973,"url":"https://github.com/angelmunoz/jdeck","last_synced_at":"2025-04-13T10:22:16.208Z","repository":{"id":263283329,"uuid":"889895166","full_name":"AngelMunoz/JDeck","owner":"AngelMunoz","description":"A STJ Wraper library for JSON decoding for F#  types","archived":false,"fork":false,"pushed_at":"2024-11-22T06:52:33.000Z","size":100,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T03:41:07.358Z","etag":null,"topics":["decoding","dotnet","fsharp","json","jsonserialization","systemtextjson","wrapper-library","wrappper"],"latest_commit_sha":null,"homepage":"https://angelmunoz.github.io/JDeck/","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/AngelMunoz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-17T14:16:13.000Z","updated_at":"2024-11-24T11:20:16.000Z","dependencies_parsed_at":"2024-11-17T15:28:21.513Z","dependency_job_id":"72e59d0f-8bf4-44ba-91fd-7532793adc63","html_url":"https://github.com/AngelMunoz/JDeck","commit_stats":null,"previous_names":["angelmunoz/jdeck"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngelMunoz%2FJDeck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngelMunoz%2FJDeck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngelMunoz%2FJDeck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngelMunoz%2FJDeck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AngelMunoz","download_url":"https://codeload.github.com/AngelMunoz/JDeck/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248696232,"owners_count":21147093,"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":["decoding","dotnet","fsharp","json","jsonserialization","systemtextjson","wrapper-library","wrappper"],"created_at":"2024-11-20T08:04:43.274Z","updated_at":"2025-04-13T10:22:16.171Z","avatar_url":"https://github.com/AngelMunoz.png","language":"F#","readme":"# JDeck a System.Text.Json wrapper\n\nJDeck is a [Thoth.Json]-like Json decoder based on `System.Text.Json` in a single file with no external\ndependencies. Plays well with other libraries that use `System.Text.Json` like [FSharp.SystemTextJson]\n\n\u003e **Note:** While JDeck has no dependencies to start working right away, it is recommended to\n\u003e use [FsToolkit.ErrorHandling]\n\n## Usage\n\nFor most F# types, you can use the `Decode.auto` function to decode JSON as shown below:\n\n```fsharp\n#r \"nuget: JDeck, 1.0.0-beta-*\"\n\nopen JDeck\n\ntype Person = {\n  name: string\n  age: int\n  emails: string list\n}\nlet json = \"\"\"{\"name\": \"Alice\", \"age\": 30, \"emails\": [\"alice@name.com\", \"alice@age.com\"] }\"\"\"\n\nlet result: Result\u003cPerson, DecodeError\u003e = Decoding.auto(json)\n\nmatch result with\n| Ok person -\u003e printfn $\"Person: %A{person}\"\n| Error err -\u003e printfn $\"Error: %A{err}\"\n```\n\nIn cases where the data is inconclusive, you deserialize Discriminated Unions or does not play well with F# immutability, you can create a manual decoder.\n\n```fsharp\n#r \"nuget: JDeck, 1.0.0-beta-*\"\n\nopen System.Text.Json\nopen JDeck\n\ntype Person = {\n  Name: string\n  Age: int\n  Emails: string list\n}\ntype ServerResponse = { Data: Person; Message: string }\n\nlet personDecoder: Decoder\u003cPerson\u003e = fun  person -\u003e decode {\n  let! name = person |\u003e Required.Property.get(\"name\", Optional.string)\n  and! age = person |\u003e Required.Property.get(\"age\", Required.int)\n  and! emails = person |\u003e Required.Property.list(\"emails\", Optional.string)\n  return {\n    Name = name |\u003e Option.defaultValue \"\u003cmissing name\u003e\"\n    Age = age\n    // Remove any optional value from the list\n    Emails = emails |\u003e List.choose id\n  }\n}\n// Inconclusive data coming from the server\nlet person = \"\"\"{\"name\": null, \"age\": 30, \"emails\": [\"alice@name.com\", \"alice@age.com\", null] }\"\"\"\n\nlet result: Result\u003cServerResponse, DecodeError\u003e =\n  // ServerResponse will decode automatically while Person will use the custom decoder\n  Decoding.auto(\n    $$\"\"\"{ \"data\": {{person}}, \"message\": \"Success\" }\"\"\",\n    // Include your own decoder\n    JsonSerializerOptions(PropertyNameCaseInsensitive = true) |\u003e Codec.useDecoder personDecoder\n  )\n\nmatch result with\n| Ok person -\u003e printfn $\"Person: %A{person}\"\n| Error err -\u003e printfn $\"Error: %A{err}\"\n```\n\n\n## Acknowledgements\n\nNothing is done in the void, in this case I'd like to thank the following libraries for their inspiration and ideas:\n\n- [Thoth.Json] for the inspiration and a cross-runtime solution to JSON decoding, compatible with F#, JS, and Python.\n- [FsToolkit.ErrorHandling] for the general mechanism for dealing with Result types and Computation expressions\n\n[Thoth.Json]: https://github.com/thoth-org/Thoth.Json\n[FSharp.SystemTextJson]: https://github.com/Tarmil/FSharp.SystemTextJson\n[FsToolkit.ErrorHandling]: https://github.com/demystifyfp/FsToolkit.ErrorHandling\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelmunoz%2Fjdeck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangelmunoz%2Fjdeck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelmunoz%2Fjdeck/lists"}