Linh.JsonKit 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package Linh.JsonKit --version 1.0.6
                    
NuGet\Install-Package Linh.JsonKit -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Linh.JsonKit" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linh.JsonKit" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Linh.JsonKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Linh.JsonKit --version 1.0.6
                    
#r "nuget: Linh.JsonKit, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Linh.JsonKit@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Linh.JsonKit&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Linh.JsonKit&version=1.0.6
                    
Install as a Cake Tool

Linh.JsonKit: A Powerful and Flexible JSON Toolkit for .NET

NuGet Version NuGet Downloads

A flexible and high-performance JSON toolkit for .NET, designed to supercharge your serialization and deserialization tasks.

Linh.JsonKit acts as a powerful facade over System.Text.Json, seamlessly integrating features and types from Newtonsoft.Json and SpanJson. It provides a single, fluent API that is easy to use, highly configurable, and solves common JSON pain points right out of the box.


Key Features

  • Universal API: Use consistent .ToJson() and .FromJson<T>() methods for any object, including JToken, JsonNode, and more.
  • Powerful Naming Conventions: Easily switch between PascalCase, camelCase, snake_case, and kebab-case.
  • JSON Path Queries: Read deeply nested values from JsonNode or JsonElement using a simple path syntax like "user.address[0].city".
  • Smart Dynamic Deserialization: Say goodbye to JsonElement! Linh.JsonKit intelligently deserializes dynamic JSON into Dictionary<string, object> and List<object> with native .NET types (long, bool, string, etc.).
  • High-Performance SpanJson Helpers: Direct access to SpanJson's ultra-fast UTF-8 (byte[]) and UTF-16 (string) serializers for performance-critical scenarios.
  • Full Interoperability: Work with objects containing mixed types from System.Text.Json, Newtonsoft.Json, and SpanJson.
  • Advanced Reference Loop Handling: Full control over circular references with Throw, Ignore, or Preserve options.

Installation

Install the package via the .NET CLI or NuGet Package Manager.

dotnet add package Linh.JsonKit

Examples

1. Universal Serialization & Deserialization (JConvert)

The core API is designed for simplicity and power.

using Linh.JsonKit.Json;

public class User { public int UserId { get; set; } public string FullName { get; set; } }
var user = new User { UserId = 101, FullName = "John Doe" };

// Serialize to snake_case for a Python/Ruby API
string snakeCaseJson = user.ToJson(
    convention: JConvert.NamingConvention.SnakeCaseLower,
    writeIndented: true
);
// -> { "user_id": 101, "full_name": "John Doe" }

// Smartly deserialize back to a dictionary with native types
var data = snakeCaseJson.FromJson<Dictionary<string, object>>();
long userId = (long)data["user_id"]; // It's a long, not a JsonElement!

2. Reading Nested Values (JPath)

No more tedious manual navigation. Query your JSON documents directly.

using Linh.JsonKit.Json;
using System.Text.Json.Nodes;

string json = @"{ ""user"": { ""history"": [ { ""ts"": ""2023-01-10"" }, { ""ts"": ""2023-01-11"" } ] } }";
JsonNode? root = JsonNode.Parse(json);

// Get the timestamp of the second history event
if (JPath.TryGetValueByPath(root, "user.history[1].ts", out string? timestamp))
{
    Console.WriteLine($"Found timestamp: {timestamp}"); // -> Found timestamp: 2023-01-11
}

3. High-Performance Serialization with SpanJson Helpers

For performance-critical paths, use the direct SpanJson helpers to work with byte[].

using Linh.JsonKit.Json;

var user = new User { UserId = 202, FullName = "Jane Smith" };

// Serialize directly to a UTF-8 byte array (extremely fast)
byte[] utf8Bytes = user.ToJsonUtf8Bytes();

// Deserialize back from the byte array
var deserializedUser = utf8Bytes.FromJsonUtf8<User>();

Console.WriteLine(deserializedUser.FullName); // -> Jane Smith

API Reference

JConvert — Main Converters

Method Signature Description
ToJson ToJson(this object?, NamingConvention, ...) Serialize any object with naming and loop handling.
FromJson<T> FromJson<T>(this string?) Smart deserialize string to an object of type T.
FromBytes<T> FromBytes<T>(this byte[]?) Smart deserialize byte array to an object of type T.
ToJson(JToken) ToJson(this JToken?, NamingConvention, ...) Fast-path serialize JToken using Newtonsoft.Json.
NamingConvention & ReferenceLoopHandling Enums
  • NamingConvention: Unchanged, PascalCase, CamelCase, SnakeCaseLower, KebabCaseLower
  • ReferenceLoopHandling: Throw, Ignore, Preserve

JConvert — SpanJson Helpers

Method Signature Description
ToJsonUtf16<T> ToJsonUtf16<T>(this T) Serialize to a UTF-16 JSON string using SpanJson.
ToJsonUtf8Bytes<T> ToJsonUtf8Bytes<T>(this T) Serialize to a UTF-8 byte array using SpanJson (very fast).
FromJsonUtf16<T> FromJsonUtf16<T>(this string) Deserialize from a UTF-16 string using SpanJson.
FromJsonUtf8<T> FromJsonUtf8<T>(this byte[]) Deserialize from a UTF-8 byte array using SpanJson.

JPath — JSON Path Reader

Method Signature Description
TryGetValueByPath<T> TryGetValueByPath<T>(this JsonElement, ReadOnlySpan<char>, out T?) Read a nested value from a JsonElement.
TryGetValueByPath<T> TryGetValueByPath<T>(this JsonNode?, ReadOnlySpan<char>, out T?) Read a nested value from a JsonNode.

Path Syntax: Use dot notation for properties and bracket notation for array indices ("user.history[1].time").


Dependencies

License

MIT © Linh Nguyen – Free to use, modify, and distribute.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Linh.JsonKit:

Package Downloads
Linh.CodeEngine

A powerful .NET 8 library for compiling and executing C# code dynamically at runtime. This engine supports loading modules from strings or files, managing them with different lifetimes (Singleton, Scoped, Transient), and provides a ready-to-use API controller for easy integration into ASP.NET Core applications. It's designed for building extensible systems like plugin platforms or dynamic rule engines.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 112 7/17/2025
1.0.6 128 6/27/2025