Soenneker.Utils.Json
11.0.2797
Prefix Reserved
dotnet add package Soenneker.Utils.Json --version 11.0.2797
NuGet\Install-Package Soenneker.Utils.Json -Version 11.0.2797
<PackageReference Include="Soenneker.Utils.Json" Version="11.0.2797" />
<PackageVersion Include="Soenneker.Utils.Json" Version="11.0.2797" />
<PackageReference Include="Soenneker.Utils.Json" />
paket add Soenneker.Utils.Json --version 11.0.2797
#r "nuget: Soenneker.Utils.Json, 11.0.2797"
#:package Soenneker.Utils.Json@11.0.2797
#addin nuget:?package=Soenneker.Utils.Json&version=11.0.2797
#tool nuget:?package=Soenneker.Utils.Json&version=11.0.2797
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.1322)
- Soenneker.Utils.File (>= 11.0.2348)
- Soenneker.Utils.Runtime (>= 11.0.1175)
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.2797 | 14,801 | 11/19/2026 |
| 11.0.2796 | 1,599 | 11/18/2026 |
| 11.0.2794 | 992 | 11/18/2026 |
| 11.0.2793 | 1,284 | 11/18/2026 |
| 11.0.2792 | 1,452 | 11/18/2026 |
| 11.0.2791 | 1,243 | 11/18/2026 |
| 11.0.2790 | 13,561 | 11/15/2026 |
| 11.0.2789 | 5,976 | 11/14/2026 |
| 11.0.2787 | 12,790 | 11/11/2026 |
| 11.0.2786 | 3,993 | 11/11/2026 |
| 11.0.2785 | 3,788 | 11/11/2026 |
| 11.0.2784 | 1,436 | 11/11/2026 |
| 11.0.2783 | 1,848 | 11/11/2026 |
| 11.0.2782 | 509 | 11/11/2026 |
| 11.0.2781 | 203 | 11/11/2026 |
| 11.0.2780 | 2,698 | 11/11/2026 |
| 11.0.2779 | 23,389 | 11/3/2026 |
| 11.0.2778 | 2,360 | 11/3/2026 |
| 11.0.2777 | 2,046 | 11/3/2026 |
| 11.0.2776 | 1,468 | 11/3/2026 |
Updated Multiple NuGet packages