{"id":24524186,"url":"https://github.com/bytedev/bytedev.json.systemtextjson","last_synced_at":"2025-04-14T12:54:13.329Z","repository":{"id":134772939,"uuid":"392552011","full_name":"ByteDev/ByteDev.Json.SystemTextJson","owner":"ByteDev","description":".NET Standard library of functionality built on System.Text.Json.","archived":false,"fork":false,"pushed_at":"2024-03-15T07:47:33.000Z","size":56,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T02:04:35.344Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/ByteDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-08-04T04:48:53.000Z","updated_at":"2022-11-06T11:15:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"529a9cbd-624e-422e-95f4-21bacde5ed37","html_url":"https://github.com/ByteDev/ByteDev.Json.SystemTextJson","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Json.SystemTextJson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Json.SystemTextJson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Json.SystemTextJson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteDev%2FByteDev.Json.SystemTextJson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ByteDev","download_url":"https://codeload.github.com/ByteDev/ByteDev.Json.SystemTextJson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248885618,"owners_count":21177627,"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-01-22T04:18:46.997Z","updated_at":"2025-04-14T12:54:13.292Z","avatar_url":"https://github.com/ByteDev.png","language":"C#","readme":"[![Build status](https://ci.appveyor.com/api/projects/status/github/bytedev/ByteDev.Json.SystemTextJson?branch=master\u0026svg=true)](https://ci.appveyor.com/project/bytedev/ByteDev-Json-SystemTextJson/branch/master)\n[![NuGet Package](https://img.shields.io/nuget/v/ByteDev.Json.SystemTextJson.svg)](https://www.nuget.org/packages/ByteDev.Json.SystemTextJson)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/ByteDev/ByteDev.Json.SystemTextJson/blob/master/LICENSE)\n\n# ByteDev.Json.SystemTextJson\n\n.NET Standard library of functionality built on [System.Text.Json](https://www.nuget.org/packages/System.Text.Json/).\n\n## Installation\n\nByteDev.Json.SystemTextJson is hosted as a package on nuget.org.  To install from the Package Manager Console in Visual Studio run:\n\n`Install-Package ByteDev.Json.SystemTextJson`\n\nFurther details can be found on the [nuget page](https://www.nuget.org/packages/ByteDev.Json.SystemTextJson/).\n\n## Release Notes\n\nReleases follow semantic versioning.\n\nFull details of the release notes can be viewed on [GitHub](https://github.com/ByteDev/ByteDev.Json.SystemTextJson/blob/master/docs/RELEASE-NOTES.md).\n\n## Usage\n\nAll custom `JsonConverter` types are in namespace `ByteDev.Json.SystemTextJson.Serialization`.\n\n---\n\n### StringToDateTimeJsonConverter\n\nConverter allows a JSON string representation of a date time to be automatically converted to a `DateTime` and back again using the supplied date time format string.\n\n```csharp\npublic class TestEntity\n{\n    [JsonPropertyName(\"datetime\")]\n    public DateTime MyDateTime { get; set; }\n}\n```\n\n```csharp\nvar converter = new StringToDateTimeJsonConverter(\"yyyy-MM-dd HH:mm:ss\");\n\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(converter);\n\nstring json = \"{\\\"datetime\\\":\\\"2022-01-12 09:59:20\\\"}\";\n\nvar obj = JsonSerializer.Deserialize\u003cTestEntity\u003e(json, options);\n\nvar newJson = JsonSerializer.Serialize(obj, options);\n\n// newJson == json\n```\n\n---\n\n### UnixEpochTimeToDateTimeJsonConverter\n\nConverter allows a JSON number representation of a Unix epoch time to be automatically converted to a `DateTime` and back again.\n\nBoth Unix epoch times as seconds or milliseconds are supported.\n\nThe converter assumes that the `DateTime` is UTC.\n\n```csharp\npublic class TestEntity\n{\n    [JsonPropertyName(\"datetime\")]\n    public DateTime MyDateTime { get; set; }\n}\n```\n\n```csharp\nvar converter = new UnixEpochTimeToDateTimeJsonConverter\n{\n    Precision = UnixEpochTimePrecision.Seconds\n};\n\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(converter);\n\nstring json = \"{\\\"datetime\\\":1641974376}\";\n\nvar obj = JsonSerializer.Deserialize\u003cTestEntity\u003e(json, options);\n\nvar newJson = JsonSerializer.Serialize(obj, options);\n\n// newJson == json\n```\n\n---\n\n### EnumJsonConverter\n\nConverter allows a JSON number or string representation of an enum to be automatically converted to a specified `Enum`.\n\nAs well as supporting both enum value (number) and name (string) alias string names can also be specified through use of `JsonEnumStringValueAttribute`.\n\n```csharp\npublic enum LightSwitch\n{\n    On = 1,\n        \n    [JsonEnumStringValue(\"switchOff\")]\n    Off = 2,\n\n    Faulty = 3\n}\n\npublic class MyHouse\n{\n    [JsonPropertyName(\"lights\")]\n    public LightSwitch BedroomLights { get; set; }\n}\n```\n\n```csharp\nvar converter = new EnumJsonConverter\u003cLightSwitch\u003e\n{\n    // false =\u003e Enum number value used\n    // true =\u003e Enum string name used \n    // (or JsonEnumStringValueAttribute value if defined)\n    WriteEnumName = true\n};\n\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(converter);\n\n// Example JSON representations:\n// - Using enum value =\u003e {\"lights\":1}\n// - Using enum name =\u003e {\"lights\":\"On\"}\n// - Using attribute name =\u003e {\"lights\":\"switchOff\"}\n\nstring json = \"{\\\"lights\\\":\\\"switchOff\\\"}\";\n\nvar obj = JsonSerializer.Deserialize\u003cMyHouse\u003e(json, options);\n\nvar newJson = JsonSerializer.Serialize(obj, options);\n\n// newJson == json\n```\n\n---\n\n### NumberToBoolJsonConverter\n\nConverter allows a JSON number (integer) to be automatically converted to a .NET `Boolean`.\n\n```csharp\npublic class BoolEntity\n{\n    [JsonPropertyName(\"myBool\")]\n    public bool MyBool { get; set; }\n}\n```\n\n```csharp\n// Optional true/false integer representations params\nvar converter = new NumberToBoolJsonConverter();\n\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(converter);\n\nstring json = \"{\\\"myBool\\\":1}\";\n\nvar obj = JsonSerializer.Deserialize\u003cBoolEntity\u003e(json, options);\n\n// obj.MyBool == true\n\nvar newJson = JsonSerializer.Serialize(obj, options);\n\n// newJson == json\n```\n\n---\n\n### StringToBoolJsonConverter \u0026 StringToNullableBoolJsonConverter\n\nConverter allows a JSON string to be automatically converted to a .NET `Boolean`.\n\n```csharp\npublic class BoolEntity\n{\n    [JsonPropertyName(\"myBool\")]\n    public bool MyBool { get; set; }\n}\n```\n\n```csharp\nvar converter = new StringToBoolJsonConverter(\"N\", \"Y\");\n\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(converter);\n\nstring json = \"{\\\"myBool\\\":\\\"Y\\\"}\";\n\nvar obj = JsonSerializer.Deserialize\u003cBoolEntity\u003e(json, options);\n\n// obj.MyBool == true\n\nvar newJson = JsonSerializer.Serialize(obj, options);\n\n// newJson == json\n```\n\nThe package also contains the similar converter `StringToNullableBoolJsonConverter`. \n\nThis works in the same way to `StringToBoolJsonConverter` but converts to a .NET Nullable Boolean type. \n\nThe converter's constructor takes an additional third string parameter to represent the null value in JSON.\n\n---\n\n### StringToGuidJsonConverter\n\nConverter allows a JSON string to be automatically converted to a .NET `System.Guid`.\n\nSupports reading (deserializing) many different representations of Guid strings as well as specifying a write format to use when writing (serializing) to JSON.\n\n```csharp\npublic class GuidEntity\n{\n    [JsonPropertyName(\"myGuid\")]\n    public Guid MyGuid { get; set; }\n}\n```\n\n```csharp\nvar converter = new StringToGuidJsonConverter(\"N\");\n\nvar options = new JsonSerializerOptions();\noptions.Converters.Add(converter);\n\nstring json = \"{\\\"myGuid\\\":\\\"c62a82b35e0d47bf9a12b027ff56d3e3\\\"}\";\n\nvar obj = JsonSerializer.Deserialize\u003cGuidEntity\u003e(json, options);\n\n// obj.MyGuid == Guid.Parse(\"c62a82b3-5e0d-47bf-9a12-b027ff56d3e3\")\n\nvar newJson = JsonSerializer.Serialize(obj, options) ;\n\n// newJson == json\n```\n\nJSON string write formats currently supported:\n\n```\n\"D\" = \"c62a82b3-5e0d-47bf-9a12-b027ff56d3e3\"\n\"N\" = \"c62a82b35e0d47bf9a12b027ff56d3e3\"\n\"B\" = \"{c62a82b3-5e0d-47bf-9a12-b027ff56d3e3}\"\n\"P\" = \"(c62a82b3-5e0d-47bf-9a12-b027ff56d3e3)\"\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedev%2Fbytedev.json.systemtextjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytedev%2Fbytedev.json.systemtextjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedev%2Fbytedev.json.systemtextjson/lists"}