{"id":26364931,"url":"https://github.com/jjosh102/json-to-csharp-poco","last_synced_at":"2025-08-05T06:19:10.226Z","repository":{"id":271483988,"uuid":"913296878","full_name":"jjosh102/json-to-csharp-poco","owner":"jjosh102","description":"This tool provides a simple way to convert JSON data to C# POCO (Plain Old CLR Object) classes","archived":false,"fork":false,"pushed_at":"2025-03-09T23:10:07.000Z","size":65224,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T00:18:35.216Z","etag":null,"topics":["csharp","json","show","tools"],"latest_commit_sha":null,"homepage":"https://jjosh102.github.io/json-to-csharp-poco/","language":"C#","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/jjosh102.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":"2025-01-07T12:11:47.000Z","updated_at":"2025-03-09T23:08:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"61c75b17-d14e-4275-9db1-830984d7b428","html_url":"https://github.com/jjosh102/json-to-csharp-poco","commit_stats":null,"previous_names":["jjosh102/json-to-csharp-poco"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fjson-to-csharp-poco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fjson-to-csharp-poco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fjson-to-csharp-poco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjosh102%2Fjson-to-csharp-poco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jjosh102","download_url":"https://codeload.github.com/jjosh102/json-to-csharp-poco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243919294,"owners_count":20368864,"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":["csharp","json","show","tools"],"created_at":"2025-03-16T19:28:45.267Z","updated_at":"2025-03-16T19:28:45.823Z","avatar_url":"https://github.com/jjosh102.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON to C# POCO Converter\n\nA simple tool for converting JSON data into C# POCO (Plain Old CLR Object) classes with support for records, customizable property access, nullable types, and various collection types.\n\n## Features\n\n- Convert JSON to C# classes or records\n- Support for nested objects and arrays\n- Customizable property access patterns\n- Optional JSON property name attributes\n- Nullable type support\n- Required property markers\n- Default value initialization\n- Multiple array type options\n- Primary constructor support for records\n\n## Settings\n\n### Basic Settings\n\n- `Namespace`: Set the namespace for generated classes (default: \"JsonToCsharp\")\n- `RootTypeName`: Set the name for the root class/record (default: \"Root\")\n- `UseRecords`: Generate C# records instead of classes\n- `UsePrimaryConstructor`: Use primary constructor syntax for records (C# 9.0+)\n\n### Property Settings\n\n- `PropertyAccess`: Control property accessor patterns\n  - `Mutable`: Generate `{ get; set; }` properties\n  - `Immutable`: Generate `{ get; init; }` properties (C# 9.0+)\n\n- `ArrayType`: Choose collection type for arrays\n  - `IReadOnlyList\u003cT\u003e`: Immutable list interface\n  - `List\u003cT\u003e`: Standard mutable list\n  - `T[]`: Array type\n\n- `AddAttribute`: Add `[JsonPropertyName]` attributes for JSON serialization\n- `IsNullable`: Generate nullable reference types\n- `IsRequired`: Add `required` keyword to properties (C# 11.0+)\n- `IsDefaultInitialized`: Initialize properties with default values\n\n## Examples\n\n### Basic Class Generation\n\nInput JSON:\n```json\n{\n    \"name\": \"John\",\n    \"age\": 30,\n    \"isEmployee\": true\n}\n```\n\nSettings:\n```csharp\nvar options = new ConversionSettings\n{\n    Namespace = \"MyNamespace\",\n    UseRecords = false,\n    PropertyAccess = PropertyAccess.Mutable\n};\n```\n\nOutput:\n```csharp\nnamespace MyNamespace;\n\npublic class Root\n{\n    [JsonPropertyName(\"name\")]\n    public string Name { get; set; }\n    \n    [JsonPropertyName(\"age\")]\n    public int Age { get; set; }\n    \n    [JsonPropertyName(\"isEmployee\")]\n    public bool IsEmployee { get; set; }\n}\n```\n\n### Record with Primary Constructor\n\nSettings:\n```csharp\nvar options = new ConversionSettings\n{\n    UseRecords = true,\n    UsePrimaryConstructor = true,\n    AddAttribute = true\n};\n```\n\nOutput:\n```csharp\npublic record Root(\n    [property: JsonPropertyName(\"name\")] string Name,\n    [property: JsonPropertyName(\"age\")] int Age,\n    [property: JsonPropertyName(\"isEmployee\")] bool IsEmployee\n);\n```\n\n### Nullable and Required Properties\n\nSettings:\n```csharp\nvar options = new ConversionSettings\n{\n    IsNullable = true,\n    IsRequired = true,\n    PropertyAccess = PropertyAccess.Immutable\n};\n```\n\nOutput:\n```csharp\npublic class Root\n{\n    [JsonPropertyName(\"name\")]\n    public required string? Name { get; init; }\n    \n    [JsonPropertyName(\"age\")]\n    public required int? Age { get; init; }\n}\n```\n\n### Array Type Options\n\nInput JSON:\n```json\n{\n    \"items\": [\"A\", \"B\", \"C\"]\n}\n```\n\nSettings for different array types:\n```csharp\n// IReadOnlyList\noptions.ArrayType = ArrayType.IReadOnlyList;\n// Output: public IReadOnlyList\u003cstring\u003e Items { get; init; }\n\n// List\noptions.ArrayType = ArrayType.List;\n// Output: public List\u003cstring\u003e Items { get; init; }\n\n// Array\noptions.ArrayType = ArrayType.Array;\n// Output: public string[] Items { get; init; }\n```\n\n### Default Initialization\n\nSettings:\n```csharp\nvar options = new ConversionSettings\n{\n    IsDefaultInitialized = true,\n    PropertyAccess = PropertyAccess.Immutable\n};\n```\n\nOutput:\n```csharp\npublic class Root\n{\n    public string Name { get; init; } = string.Empty;\n    public IReadOnlyList\u003cstring\u003e Tags { get; init; } = [];\n    public Address Address { get; init; } = new();\n}\n```\n\n## Type Mapping\n\nThe converter automatically maps JSON types to C# types:\n- JSON strings → `string`\n- JSON numbers → `int` or `double`\n- JSON booleans → `bool`\n- JSON arrays → `IReadOnlyList\u003cT\u003e`, `List\u003cT\u003e`, or `T[]`\n- JSON objects → Nested classes/records\n- JSON dates → `DateTime`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjosh102%2Fjson-to-csharp-poco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjjosh102%2Fjson-to-csharp-poco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjosh102%2Fjson-to-csharp-poco/lists"}