{"id":16554562,"url":"https://github.com/tyrrrz/jsonextensions","last_synced_at":"2025-10-10T12:21:45.308Z","repository":{"id":111086169,"uuid":"316815710","full_name":"Tyrrrz/JsonExtensions","owner":"Tyrrrz","description":"Extensions for System.Text.Json","archived":false,"fork":false,"pushed_at":"2025-10-02T13:12:58.000Z","size":116,"stargazers_count":35,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-02T15:12:27.901Z","etag":null,"topics":["dotnet","dotnet-core","dotnet-standard","extensions","json","parser"],"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/Tyrrrz.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","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},"funding":{"github":"Tyrrrz","patreon":"Tyrrrz","custom":["tyrrrz.me/donate"]}},"created_at":"2020-11-28T20:23:48.000Z","updated_at":"2025-10-02T13:13:02.000Z","dependencies_parsed_at":"2023-04-20T19:32:15.219Z","dependency_job_id":"c7919731-2c55-4ac1-b8f2-041f4d567ac2","html_url":"https://github.com/Tyrrrz/JsonExtensions","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Tyrrrz/JsonExtensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyrrrz%2FJsonExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyrrrz%2FJsonExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyrrrz%2FJsonExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyrrrz%2FJsonExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tyrrrz","download_url":"https://codeload.github.com/Tyrrrz/JsonExtensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyrrrz%2FJsonExtensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003896,"owners_count":26083641,"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-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["dotnet","dotnet-core","dotnet-standard","extensions","json","parser"],"created_at":"2024-10-11T19:51:48.117Z","updated_at":"2025-10-10T12:21:45.258Z","avatar_url":"https://github.com/Tyrrrz.png","language":"C#","funding_links":["https://github.com/sponsors/Tyrrrz","https://patreon.com/Tyrrrz","tyrrrz.me/donate"],"categories":[],"sub_categories":[],"readme":"# JsonExtensions\n\n[![Status](https://img.shields.io/badge/status-maintenance-ffd700.svg)](https://github.com/Tyrrrz/.github/blob/master/docs/project-status.md)\n[![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://tyrrrz.me/ukraine)\n[![Build](https://img.shields.io/github/actions/workflow/status/Tyrrrz/JsonExtensions/main.yml?branch=master)](https://github.com/Tyrrrz/JsonExtensions/actions)\n[![Coverage](https://img.shields.io/codecov/c/github/Tyrrrz/JsonExtensions/master)](https://codecov.io/gh/Tyrrrz/JsonExtensions)\n[![Version](https://img.shields.io/nuget/v/JsonExtensions.svg)](https://nuget.org/packages/JsonExtensions)\n[![Downloads](https://img.shields.io/nuget/dt/JsonExtensions.svg)](https://nuget.org/packages/JsonExtensions)\n[![Discord](https://img.shields.io/discord/869237470565392384?label=discord)](https://discord.gg/2SUWKFnHSm)\n[![Fuck Russia](https://img.shields.io/badge/fuck-russia-e4181c.svg?labelColor=000000)](https://twitter.com/tyrrrz/status/1495972128977571848)\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd width=\"99999\" align=\"center\"\u003eDevelopment of this project is entirely funded by the community. \u003cb\u003e\u003ca href=\"https://tyrrrz.me/donate\"\u003eConsider donating to support!\u003c/a\u003e\u003c/b\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n**JsonExtensions** is a library that provides a set of helpful utilities for types defined in the [`System.Text.Json`](https://docs.microsoft.com/en-us/dotnet/api/system.text.json) namespace.\n\n## Terms of use\u003csup\u003e[[?]](https://github.com/Tyrrrz/.github/blob/master/docs/why-so-political.md)\u003c/sup\u003e\n\nBy using this project or its source code, for any purpose and in any shape or form, you grant your **implicit agreement** to all the following statements:\n\n- You **condemn Russia and its military aggression against Ukraine**\n- You **recognize that Russia is an occupant that unlawfully invaded a sovereign state**\n- You **support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas**\n- You **reject false narratives perpetuated by Russian state propaganda**\n\nTo learn more about the war and how you can help, [click here](https://tyrrrz.me/ukraine). Glory to Ukraine! 🇺🇦\n\n## Install\n\n- 📦 [NuGet](https://nuget.org/packages/JsonExtensions): `dotnet add package JsonExtensions`\n\n## Usage\n\n### Parsing JsonElement\n\nYou can use the static methods on the `Json` class to parse JSON directly into a stateless `JsonElement` instance, without having to deal with `JsonDocument` in the process:\n\n```csharp\nusing JsonExtensions;\n\nvar jsonRaw = \"{ \\\"foo\\\": \\\"bar\\\" }\";\n\nvar jsonElement = Json.Parse(jsonRaw); // returns JsonElement\nvar jsonElement = Json.TryParse(jsonRaw); // returns null in case of invalid JSON\n```\n\n### Null-safe reading\n\nThis library offers many extension methods for `JsonElement` that allow you to read its content in a more fault-tolerant way:\n\n```csharp\nusing JsonExtensions.Reading;\n\nvar jsonElement = ...;\n\n// Gets a property or returns null if:\n// - element is not an object\n// - property does not exist\n// - property value is null\nvar maybeProperty = jsonElement.GetPropertyOrNull(\"prop\");\n\n// Gets an array child or returns null if:\n// - element is not an array\n// - index is out of bounds\n// - child is null\nvar maybeChild = jsonElement.GetByIndexOrNull(3);\n\n// Gets the value converted into the specified type or returns null if:\n// - element is null\n// - element kind does not match the specified type\n// - the value cannot be parsed into the specified type\nvar maybeString = jsonElement.GetStringOrNull();\nvar maybeInt32 = jsonElement.GetInt32OrNull();\nvar maybeGuid = jsonElement.GetGuidOrNull();\n\n// Gets the value coerced into the specified type or returns null if:\n// - element is null\n// - element kind does not match the specified type or a string\n// - the value cannot be parsed into the specified type\nvar maybeInt32Coerced = jsonElement.GetInt32CoercedOrNull();\nvar maybeDoubleCoerced = jsonElement.GetDoubleCoercedOrNull();\n\n// Enumerates an array or returns null if:\n// - element is not an array\nvar arrayEnumerator = jsonElement.EnumerateArrayOrNull();\n\n// Enumerates an object or returns null if:\n// - element is not an object\nvar objectEnumerator = jsonElement.EnumerateObjectOrNull();\n\n// Enumerates an array or returns an empty enumerator if:\n// - element is not an array\nforeach (var child in jsonElement.EnumerateArrayOrEmpty())\n{\n    // ...\n}\n\n// Enumerates an object or returns an empty enumerator if:\n// - element is not an object\nforeach (var (name, child) in jsonElement.EnumerateObjectOrEmpty())\n{\n    // ...\n}\n```\n\nMost of these methods can also be chained together using the null-conditional operator:\n\n```csharp\n// Returns null if:\n// - element is not an object\n// - property does not exist\n// - property value is null\n// - property value cannot be converted into the specified type\nvar maybeInt32 = jsonElement.GetPropertyOrNull(\"prop\")?.GetInt32OrNull();\n```\n\n### Null-safe writing\n\nSimilarly, there are also extension methods for `Utf8JsonWriter` that allow writing nullable versions of common value types:\n\n```csharp\nusing JsonExtensions.Writing;\n\nvar writer = new Utf8JsonWriter(...);\n\n// Writes \"prop\":true\nwriter.WriteBoolean(\"prop\", new bool?(true));\n\n// Writes \"prop\":null\nwriter.WriteBoolean(\"prop\", new bool?());\n```\n\n### Parsing JSON from HTTP\n\nTo make it easier to read JSON that comes from HTTP responses, this library also provides a few extension methods for `HttpContent` and `HttpClient`:\n\n```csharp\nusing JsonExtensions.Http;\n\nvar http = new HttpClient();\n\n// Send a GET request and retrieve JSON directly\nvar json = await http.GetJsonAsync(\"...\"); // returns JsonElement\n\n// Read JSON from content\nusing var request = new HttpRequestMessage(HttpMethod.Post, \"...\");\nusing var response = await http.SendAsync(request);\nvar json = await response.Content.ReadAsJsonAsync(); // returns JsonElement\n```\n\n### Accessing children by path\n\nUsing `jsonElement.GetPropertyByPathOrNull(...)` or `jsonElement.GetPropertyByPath(...)`, you can get an inner child by its path:\n\n```csharp\nvar json = Json.Parse(\"{\\\"foo\\\":{\\\"bar\\\":{\\\"baz\\\":13}}}\");\n\nvar child = json.GetPropertyByPath(\"foo.bar.baz\");\n\nvar value = child.GetInt32(); // 13\n```\n\n\u003e **Warning**:\n\u003e Note this only supports basic paths involving child access operators.\n\u003e It doesn't (yet) have full support for JPath.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyrrrz%2Fjsonextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyrrrz%2Fjsonextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyrrrz%2Fjsonextensions/lists"}