{"id":15060906,"url":"https://github.com/thorium/fsharp.data.jsonprovider.serializer","last_synced_at":"2025-07-23T06:04:17.497Z","repository":{"id":208707341,"uuid":"722299209","full_name":"Thorium/FSharp.Data.JsonProvider.Serializer","owner":"Thorium","description":"Plugin to replace FSharp.Data.JsonProvider default serialization with fast System.Text.Json","archived":false,"fork":false,"pushed_at":"2025-05-10T09:16:15.000Z","size":37,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-22T06:35:57.444Z","etag":null,"topics":["data","fsharp","json","typeprovider"],"latest_commit_sha":null,"homepage":"","language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Thorium.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,"zenodo":null}},"created_at":"2023-11-22T20:55:21.000Z","updated_at":"2025-05-10T09:16:18.000Z","dependencies_parsed_at":"2025-05-08T15:34:45.975Z","dependency_job_id":null,"html_url":"https://github.com/Thorium/FSharp.Data.JsonProvider.Serializer","commit_stats":null,"previous_names":["thorium/fsharp.data.jsonprovider.serializer"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Thorium/FSharp.Data.JsonProvider.Serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thorium%2FFSharp.Data.JsonProvider.Serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thorium%2FFSharp.Data.JsonProvider.Serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thorium%2FFSharp.Data.JsonProvider.Serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thorium%2FFSharp.Data.JsonProvider.Serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thorium","download_url":"https://codeload.github.com/Thorium/FSharp.Data.JsonProvider.Serializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thorium%2FFSharp.Data.JsonProvider.Serializer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266626115,"owners_count":23958344,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["data","fsharp","json","typeprovider"],"created_at":"2024-09-24T23:06:18.831Z","updated_at":"2025-07-23T06:04:17.467Z","avatar_url":"https://github.com/Thorium.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# FSharp.Data.JsonProvider.Serializer\n\nNuGet package: https://www.nuget.org/packages/FSharp.Data.JsonProvider.Serializer/\nThis is not an independent package; you still use your current JsonProvider.\n\nThis will provide utilities to use the fast `System.Text.Json` library to serialize the `FSharp.Data.JsonProvider` items.\n\n - FSharp.Data: https://fsprojects.github.io/FSharp.Data/\n - System.Text.Json: https://www.nuget.org/packages/System.Text.Json\n\nMotivation: Serialization speed.\nTypically, JSON Serialization is used either so that the user is watching a progress-bar, or in a big batch-process.\n\nCurrent FSharp.Data is using a custom Json-serializer.\n\nWe need a compromise having the convenience of F# JsonProvider, but the speed of System.Text.Json.\n\nThe idea is to be in-replacement for current functions:\n\n## Reading values to type provider (Deserialization)\n\nCurrent FSharp.Data.JsonProvider:\n\n```fsharp\ntype MyJsonType = FSharp.Data.JsonProvider\u003c\"\"\"{ \"model\": \"...\" } \"\"\"\u003e\n\nlet fromJson (response:string) = MyJsonType.Parse response\n\n```\n\nUsing this library:\n\n```fsharp\ntype MyJsonType = FSharp.Data.JsonProvider\u003c\"\"\"{ \"model\": \"...\" } \"\"\"\u003e\n\nlet fromJson (response:string) = MyJsonType.Load (Serializer.Deserialize response)\n\n```\n\n\n## Saving values from type provider (Serialization)\n\nCurrent FSharp.Data.JsonProvider:\n\n```fsharp\ntype MyJson = FSharp.Data.JsonProvider\u003c\"\"\"{ \"model\": \"...\" } \"\"\"\u003e\n\nlet toJson mymodel = mymodel.JsonValue.ToString()\n\n```\n\nUsing this library:\n\n```fsharp\ntype MyJson = FSharp.Data.JsonProvider\u003c\"\"\"{ \"model\": \"...\" } \"\"\"\u003e\n\nlet toJson mymodel = Serializer.Serialize (mymodel.JsonValue)\n\n```\n\nBesides this, you can continue using your existing JsonProvider implementation as is.\nCurrently, it uses System.Text.Json style of encoding the quote characters, etc. but if you want to customize\nyour serialization more, you can set JsonReaderOptions and JsonWriterOptions as parameters.\n\n## Initial Benchmarks\n\nFSharp.Data 6.3, System.Text.Json 8.0\n\nTest-case:\n- Read JSON to JsonProvider. (Serialization)\n- Verify a property\n- Save JSON back to a string. (Deserialization)\n\nTested with small JSON file, and with Stripe OpenAPI spec file (+5MB of JSON).\n\nBenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.2715/22H2/2022Update/SunValley2)\n13th Gen Intel Core i9-13900H, 1 CPU, 20 logical and 14 physical cores\n\n\n\n#### .NET 8.0 : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2\n\n| Method                                 | Mean          | Error         | StdDev        | Gen0      | Gen1      | Gen2      | Allocated   |\n|--------------------------------------- |--------------:|--------------:|--------------:|----------:|----------:|----------:|------------:|\n| SmallJson_JsonProvider                 |      2.789 μs |     0.0314 μs |     0.0293 μs |    0.4120 |         - |         - |     5.06 KB |\n| SmallJson_SystemTextJson               |      1.623 μs |     0.0308 μs |     0.0288 μs |    0.2651 |         - |         - |     3.27 KB |\n| ListOf1000SmallJsons_JsonProvider      |  2,849.210 μs |    25.9458 μs |    20.2568 μs |  351.5625 |  175.7813 |   58.5938 |   4224.8 KB |\n| ListOf1000SmallJsons_SystemTextJson    |  1,424.314 μs |     9.3599 μs |     8.7553 μs |  199.2188 |  199.2188 |  199.2188 |  2469.76 KB |\n| StripeJson_JsonProvider                | 83,610.123 μs | 1,667.5590 μs | 3,406.3812 μs | 5285.7143 | 4571.4286 | 1714.2857 | 60521.87 KB |\n| StripeJson_SystemTextJsonBytes         | 42,775.639 μs |   822.2020 μs | 1,009.7378 μs | 2333.3333 | 2166.6667 |  750.0000 | 44305.47 KB |\n\n\n\n#### .NET Framework 4.8 : .NET Framework 4.8.1 (4.8.9181.0), X64 RyuJIT VectorSize=256\n\n| Method                                 | Mean           | Error         | StdDev        | Gen0      | Gen1      | Gen2      | Allocated   |\n|--------------------------------------- |---------------:|--------------:|--------------:|----------:|----------:|----------:|------------:|\n| SmallJson_JsonProvider                 |       6.613 μs |     0.0554 μs |     0.0518 μs |    0.8621 |         - |         - |     5.32 KB |\n| SmallJson_SystemTextJson               |       4.832 μs |     0.0542 μs |     0.0480 μs |    0.5493 |         - |         - |      3.4 KB |\n| ListOf1000SmallJsons_JsonProvider      |   7,052.777 μs |    53.6100 μs |    47.5238 μs |  695.3125 |  343.7500 |   54.6875 |   4465.7 KB |\n| ListOf1000SmallJsons_SystemTextJson    |   4,453.736 μs |    43.9446 μs |    41.1058 μs |  390.6250 |  195.3125 |  195.3125 |  2587.36 KB |\n| StripeJson_JsonProvider                | 107,016.899 μs | 2,094.9813 μs | 3,500.2432 μs | 8200.0000 | 3800.0000 | 1400.0000 | 61612.22 KB |\n| StripeJson_SystemTextJsonBytes         |  77,002.389 μs | 1,531.7106 μs | 2,559.1443 μs | 4285.7143 | 2285.7143 | 1000.0000 | 45245.97 KB |\n\n\nTo run the test: dotnet run --project tests\\Benchmarks\\BenchmarkTests.fsproj --configuration=Release --framework=net8.0\n\n\n## API\n\nFSharp.Data uses internally class called `FSharp.Data.JsonValue` to model the JSON domain.\n\n#### From JSON to JsonProvider\n\n- `Deserialize`: string to FSharp.Data.JsonValue\n- `DeserializeWith`: string and System.Text.Json.JsonReaderOptions to FSharp.Data.JsonValue\n- `DeserializeBytes`: byte array to FSharp.Data.JsonValue\n- `DeserializeBytesWith`: byte array and System.Text.Json.JsonReaderOptions to FSharp.Data.JsonValue\n\n#### From JsonProvider to JSON\n\n- `Serialize`: FSharp.Data.JsonValue to string\n- `SerializeWith`: FSharp.Data.JsonValue and System.Text.Json.JsonWriterOptions to string\n- `SerializeBytes`: FSharp.Data.JsonValue to byte array\n- `SerializeBytesWith`: FSharp.Data.JsonValue and System.Text.Json.JsonWriterOptions to byte array\n\n#### From JsonProvider to JSON, Streaming\n\nWith streaming support, you can send JSON-data to output stream record-per-record.\n\n- `SerializeStream`: destination stream, FSharp.Data.JsonValue\n- `SerializeStreamWith`: destination stream, FSharp.Data.JsonValue and System.Text.Json.JsonWriterOptions\n\nStreaming may maintain the same performance characteristics but reduce memory allocation a bit and provide partially consumable results faster if the JSON is large and the client supports streaming.\n\n**.NET 8.0 : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2**\n\n| Method                                    | Mean          | Error         | StdDev        | Gen0      | Gen1      | Gen2      | Allocated   |\n|------------------------------------------ |--------------:|--------------:|--------------:|----------:|----------:|----------:|------------:|\n| ListOf1000SmallJsons_SystemTextJsonStream |  1,525.970 μs |    14.0992 μs |    13.1884 μs |  158.2031 |  117.1875 |   78.1250 |  2100.46 KB |\n| StripeJson_SystemTextJsonStream           | 47,112.065 μs |   805.5929 μs |   753.5521 μs | 2333.3333 | 2250.0000 |  750.0000 | 31560.25 KB |\n\n**.NET Framework 4.8 : .NET Framework 4.8.1 (4.8.9181.0), X64 RyuJIT VectorSize=256**\n\n| Method                                    | Mean           | Error         | StdDev        | Gen0      | Gen1      | Gen2      | Allocated   |\n|------------------------------------------ |---------------:|--------------:|--------------:|----------:|----------:|----------:|------------:|\n| ListOf1000SmallJsons_SystemTextJsonStream |   4,650.089 μs |    34.2087 μs |    30.3251 μs |  312.5000 |  156.2500 |   78.1250 |  2217.05 KB |\n| StripeJson_SystemTextJsonStream           |  76,921.557 μs | 1,448.2545 μs | 1,778.5866 μs | 4000.0000 | 2000.0000 | 1000.0000 | 32501.88 KB |\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorium%2Ffsharp.data.jsonprovider.serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthorium%2Ffsharp.data.jsonprovider.serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorium%2Ffsharp.data.jsonprovider.serializer/lists"}