{"id":37557179,"url":"https://github.com/guiorgy/jsonextensions","last_synced_at":"2026-01-16T09:01:04.354Z","repository":{"id":159223966,"uuid":"634552807","full_name":"Guiorgy/JsonExtensions","owner":"Guiorgy","description":".NET System.Text.Json extensions","archived":false,"fork":false,"pushed_at":"2025-11-15T23:24:45.000Z","size":79,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-13T06:58:12.139Z","etag":null,"topics":["extension","json","net"],"latest_commit_sha":null,"homepage":"","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/Guiorgy.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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-30T14:04:34.000Z","updated_at":"2025-11-15T23:24:48.000Z","dependencies_parsed_at":"2023-07-29T14:32:03.936Z","dependency_job_id":null,"html_url":"https://github.com/Guiorgy/JsonExtensions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Guiorgy/JsonExtensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guiorgy%2FJsonExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guiorgy%2FJsonExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guiorgy%2FJsonExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guiorgy%2FJsonExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Guiorgy","download_url":"https://codeload.github.com/Guiorgy/JsonExtensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guiorgy%2FJsonExtensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["extension","json","net"],"created_at":"2026-01-16T09:01:00.537Z","updated_at":"2026-01-16T09:01:04.295Z","avatar_url":"https://github.com/Guiorgy.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonExtensions\n\nA collection of extension for .NET System.Text.Json\n\n## SingleOrArrayJsonConverter\n\nA JsonConverter that deserializes both a single JSON object and a JSON array as a C# array.\n\n- With the default JsonConverter\n\n```cs\npublic sealed class Example\n{\n  [JsonConverter(typeof(SingleOrArrayJsonConverter))]\n  public string[]? Array { get; set; }\n}\n```\n\n```cs\nconst string jsonSingle = \"\"\"{\"Array\": \"single\"}\"\"\";\nvar deserializedSingle = JsonSerializer.Deserialize\u003cExample\u003e(jsonSingle);\nConsole.WriteLine($\"{deserializedSingle.Array.Length}: {deserializedSingle.Array[0]}\");\n// Output: \"1: single\"\n\nconst string jsonArray = \"\"\"{\"Array\": [\"first\", \"second\"]}\"\"\";\nvar deserializedArray = JsonSerializer.Deserialize\u003cExample\u003e(jsonArray);\nConsole.WriteLine($\"{deserializedArray.Array.Length}: {deserializedArray.Array[0]}, {deserializedArray.Array[1]}\");\n// Output: \"2: first, second\"\n```\n\n- With a custom JsonConverter\n\n```cs\npublic sealed class Person\n{\n  public string FirstName { get; }\n  public string LastName { get; }\n\n  public Person(string firstName, string lastName)\n  {\n    FirstName = firstName;\n    LastName = lastName;\n  }\n}\n\n// Converts a Person object into a \"${FirstName} ${LastName}\" string\npublic sealed class PersonJsonConverter : JsonConverter\u003cstring\u003e\n{\n  public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n  {\n    var personConverter = (JsonConverter\u003cPerson\u003e)options.GetConverter(typeof(Person));\n\n    Person? person = personConverter.Read(ref reader, typeof(Person), options);\n\n    return person != null ? $\"{person.FirstName} {person.LastName}\" : null;\n  }\n\n  public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)\n  {\n    var personConverter = (JsonConverter\u003cPerson\u003e)options.GetConverter(typeof(Person));\n\n    var split = value.Split(' ');\n    var firstName = split[0];\n    var lastName = split[1];\n    var person = new Person(firstName, lastName);\n\n    personConverter.Write(writer, person, options);\n  }\n}\n\npublic sealed class Example\n{\n  [JsonConverter(typeof(SingleOrArrayJsonConverter\u003cPersonJsonConverter\u003e))]\n  public string[]? Array { get; set; }\n}\n```\n\n```cs\nconst string jsonSingle = \"\"\"{\"Array\": {\"FirstName\": \"John\", \"LastName\": \"Smith\"}}\"\"\";\nvar deserializedSingle = JsonSerializer.Deserialize\u003cExample\u003e(json);\nConsole.WriteLine($\"{deserializedSingle.Array.Length}: {deserializedSingle.Array[0]}\");\n// Output: \"1: John Smith\"\n\nconst string jsonArray = \"\"\"{\"Array\": [{\"FirstName\": \"John\", \"LastName\": \"Smith\"}, {\"FirstName\": \"John\", \"LastName\": \"Doe\"}]}\"\"\";\nvar deserializedArray = JsonSerializer.Deserialize\u003cExample\u003e(json);\nConsole.WriteLine($\"{deserializedArray.Array.Length}: {deserializedArray.Array[0]}, {deserializedArray.Array[1]}\");\n// Output: \"2: John Smith, John Doe\"\n```\n\n## JsonMultiNameModifier\n\nA JsonPropertyNames attribute and JsonMultiNameModifier that allows mapping of multiple JSON keys to one C# property.\n\n- Allowing duplicate keys\n\n```cs\npublic sealed class User\n{\n  [JsonPropertyNames(\"UserName\", \"User\", \"Name\")]\n  public string UserName { get; set; }\n}\n```\n\n```cs\nJsonSerializerOptions jsonOptions = new()\n{\n  TypeInfoResolver = new DefaultJsonTypeInfoResolver()\n  {\n    Modifiers = { Modifiers.JsonMultiNameModifier }\n  }\n}\n\nconst string json1 = \"\"\"{\"UserName\": \"JohnSmith1\"}\"\"\";\nconst string json2 = \"\"\"{\"User\": \"JohnSmith2\"}\"\"\";\nconst string json3 = \"\"\"{\"Name\": \"JohnSmith3\"}\"\"\";\nvar deserialized = JsonSerializer.Deserialize\u003cUser\u003e(json1, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith1\"\ndeserialized = JsonSerializer.Deserialize\u003cUser\u003e(json2, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith2\"\ndeserialized = JsonSerializer.Deserialize\u003cUser\u003e(json3, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith3\"\n\nstring json = \"\"\"{\"UserName\": \"JohnSmith1\", \"User\": \"JohnSmith2\", \"Name\": \"JohnSmith3\"}\"\"\";\ndeserialized = JsonSerializer.Deserialize\u003cUser\u003e(json, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith3\"\n\njson = JsonSerializer.Serialize(deserialized, jsonOptions);\nConsole.WriteLine(json);\n// Output: '{\"UserName\":\"JohnSmith3\"}'\n```\n\n- Disallowing duplicate keys\n\n```cs\npublic sealed class User\n{\n  [JsonPropertyNames(throwOnDuplicate: true, \"UserName\", \"User\", \"Name\")]\n  public string UserName { get; set; }\n}\n```\n\n```cs\nJsonSerializerOptions jsonOptions = new()\n{\n  TypeInfoResolver = new DefaultJsonTypeInfoResolver()\n  {\n    Modifiers = { Modifiers.JsonMultiNameModifier }\n  }\n}\n\nconst string json1 = \"\"\"{\"UserName\": \"JohnSmith1\"}\"\"\";\nconst string json2 = \"\"\"{\"User\": \"JohnSmith2\"}\"\"\";\nconst string json3 = \"\"\"{\"Name\": \"JohnSmith3\"}\"\"\";\nvar deserialized = JsonSerializer.Deserialize\u003cUser\u003e(json1, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith1\"\ndeserialized = JsonSerializer.Deserialize\u003cUser\u003e(json2, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith2\"\ndeserialized = JsonSerializer.Deserialize\u003cUser\u003e(json3, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith3\"\n\ntry {\n  const string json = \"\"\"{\"UserName\": \"JohnSmith1\", \"User\": \"JohnSmith2\", \"Name\": \"JohnSmith3\"}\"\"\";\n  deserialized = JsonSerializer.Deserialize\u003cUser\u003e(json, jsonOptions);\n  Console.WriteLine(deserialized.UserName);\n} catch (JsonException) {\n  Console.WriteLine(\"Deserialize failed\");\n}\n// Output: \"Deserialize failed\"\n```\n\n- Different serialization key\n\n```cs\npublic sealed class User\n{\n  [JsonPropertyNames(serializationName: \"NickName\", \"UserName\", \"User\", \"Name\")]\n  public string UserName { get; set; }\n}\n```\n\n```cs\nJsonSerializerOptions jsonOptions = new()\n{\n  TypeInfoResolver = new DefaultJsonTypeInfoResolver()\n  {\n    Modifiers = { Modifiers.JsonMultiNameModifier }\n  }\n}\n\nstring json = \"\"\"{\"UserName\": \"JohnSmith\"}\"\"\";\nvar deserialized = JsonSerializer.Deserialize\u003cUser\u003e(json, jsonOptions);\nConsole.WriteLine(deserialized.UserName);\n// Output: \"JohnSmith\"\n\njson = JsonSerializer.Serialize(deserialized, jsonOptions);\nConsole.WriteLine(json);\n// Output: '{\"NickName\":\"JohnSmith\"}'\n```\n\n## MIT License\n\nCopyright (c) 2023 Guiorgy\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguiorgy%2Fjsonextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguiorgy%2Fjsonextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguiorgy%2Fjsonextensions/lists"}