Soenneker.Utils.Json
11.0.2779
Prefix Reserved
dotnet add package Soenneker.Utils.Json --version 11.0.2779
NuGet\Install-Package Soenneker.Utils.Json -Version 11.0.2779
<PackageReference Include="Soenneker.Utils.Json" Version="11.0.2779" />
<PackageVersion Include="Soenneker.Utils.Json" Version="11.0.2779" />
<PackageReference Include="Soenneker.Utils.Json" />
paket add Soenneker.Utils.Json --version 11.0.2779
#r "nuget: Soenneker.Utils.Json, 11.0.2779"
#:package Soenneker.Utils.Json@11.0.2779
#addin nuget:?package=Soenneker.Utils.Json&version=11.0.2779
#tool nuget:?package=Soenneker.Utils.Json&version=11.0.2779
Soenneker.Utils.Json
Serializes, deserializes, validates, formats, and safely writes JSON with System.Text.Json.
Installation
dotnet add package Soenneker.Utils.Json
Quick start
Serialization, deserialization, validation, and formatting are static operations on JsonUtil:
using Soenneker.Utils.Json;
string? json = JsonUtil.Serialize(new { Id = 42, Name = "example" });
Document? document = JsonUtil.Deserialize<Document>(json!);
if (!JsonUtil.TryDeserialize<Document>(utf8Json, out Document? parsed))
{
// The input was empty, invalid, or represented JSON null.
}
Serialization uses System.Text.Json with JsonOptionsCollection.WebOptions by default. Pass a
JsonTypeInfo<T> to use source-generated System.Text.Json metadata.
Register the service only when using the instance-based WritePretty file operation:
using Soenneker.Utils.Json.Registrars;
services.AddJsonUtilAsSingleton();
Then inject IJsonUtil and call WritePretty.
Common operations
Deserialize()- Deserializes strings, UTF-8 data, streams, or HTTP response content. Empty strings and byte spans return the default value.Serialize()- Returnsnullfor a null object; otherwise uses WebOptions unless another options profile is selected.SerializeToElement()- Serializes the value into a nullableJsonElementusing the requested options.SerializeToStream()- Serializes the object into the given stream using System.Text.Json.SerializeToUtf8Bytes()- Serializes an object to a UTF-8 encoded byte array using System.Text.Json.DeserializeFromFile()- Reads a file asynchronously and deserializes its JSON toT; JSONnullyieldsnull.SerializeToFile()- Serializes to a temporary sibling file and replaces the destination only after serialization succeeds. A null object leaves the destination unchanged.TryDeserialize()- Returnsfalsefor empty input, invalid JSON, or a deserialized null value. Supports optional source-generated metadata.IsJsonValid()- Returnstrueonly when the entire input is syntactically valid JSON; invalid input returnsfalseand can be logged.Format()- Parses and pretty-prints JSON, optionally forcing Windows CRLF line endings.WritePretty()- Reads a JSON file, formats it, and writes the result to the destination path.
The async deserialization overloads that accept a logger return the default value after other read or deserialization failures, but requested cancellation is propagated. The stream overloads leave caller-owned streams open.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Json.OptionsCollection (>= 11.0.1316)
- Soenneker.Utils.File (>= 11.0.2333)
- Soenneker.Utils.Runtime (>= 11.0.1161)
NuGet packages (35)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.Json:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.Object
A collection of helpful Object extension methods |
|
|
Soenneker.Redis.Util
The general purpose utility library leveraging Redis for all of your caching needs |
|
|
Soenneker.Cosmos.Repository
A data persistence abstraction layer for Cosmos DB |
|
|
Soenneker.Extensions.HttpResponseMessage
A collection of helpful HttpResponseMessage extension methods |
|
|
Soenneker.Utils.String
A utility library for useful String operations |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.2779 | 12,081 | 11/3/2026 |
| 11.0.2778 | 2,153 | 11/3/2026 |
| 11.0.2777 | 1,923 | 11/3/2026 |
| 11.0.2776 | 1,370 | 11/3/2026 |
| 11.0.2774 | 1,015 | 11/3/2026 |
| 11.0.2773 | 3,616 | 11/3/2026 |
| 11.0.2771 | 1,705 | 11/2/2026 |
| 11.0.2770 | 16,431 | 10/29/2026 |
| 11.0.2769 | 12,595 | 10/27/2026 |
| 11.0.2766 | 1,637 | 10/26/2026 |
| 11.0.2764 | 2,013 | 10/26/2026 |
| 11.0.2763 | 833 | 10/26/2026 |
| 11.0.2762 | 1,451 | 10/26/2026 |
| 11.0.2761 | 395 | 10/26/2026 |
| 11.0.2760 | 489 | 10/26/2026 |
| 11.0.2758 | 325 | 10/26/2026 |
| 4.0.2757 | 26,766 | 10/15/2026 |
| 4.0.2756 | 1,676 | 10/15/2026 |
| 4.0.2755 | 532 | 10/15/2026 |
| 4.0.2753 | 2,988 | 10/14/2026 |
Updated Soenneker.Utils.File to 11.0.2333