LHZ.FastJson
2.0.1-pre
dotnet add package LHZ.FastJson --version 2.0.1-pre
NuGet\Install-Package LHZ.FastJson -Version 2.0.1-pre
<PackageReference Include="LHZ.FastJson" Version="2.0.1-pre" />
<PackageVersion Include="LHZ.FastJson" Version="2.0.1-pre" />
<PackageReference Include="LHZ.FastJson" />
paket add LHZ.FastJson --version 2.0.1-pre
#r "nuget: LHZ.FastJson, 2.0.1-pre"
#:package LHZ.FastJson@2.0.1-pre
#addin nuget:?package=LHZ.FastJson&version=2.0.1-pre&prerelease
#tool nuget:?package=LHZ.FastJson&version=2.0.1-pre&prerelease
LHZ.FastJson
A lightweight and high-performance JSON serialization and deserialization library for .NET.
Installation
The following examples show different installation methods using LHZ.FastJson 2.0.0 as an example:
Package Manager
Install-Package LHZ.FastJson -Version 2.0.0
.NET CLI
dotnet add package LHZ.FastJson --version 2.0.0
Package Reference
<PackageReference Include="LHZ.FastJson" Version="2.0.0" />
Paket CLI
paket add LHZ.FastJson --version 2.0.0
Usage
Serialization with LHZ.FastJson
Example
Student student = new Student
{
NO = 1,
[JsonProperty("studentName")]
Name = "lhz",
Age = 18,
Brithday = new DateTime(2002, 1, 1)
};
string jsonStr = LHZ.FastJson.JsonConvert.Serialize(student);
Console.WriteLine(jsonStr);
Output
PS C:\Users\admin\source\repos\LHZ.FastJson\LHZ.FastJson.Test> dotnet run
{"NO":1,"studentName":"lhz","Age":18,"Brithday":"2000/1/1 0:00:00"}
Deserialization with LHZ.FastJson
Example
string str = "{\"NO\":1,\"studentName\":\"lhz\",\"Age\":18,\"Brithday\":\"2000/1/1 0:00:00\"}";
Student student = JsonConvert.Deserialize<Student>(str);
Console.WriteLine("NO:{0},Name:{1},Age:{2},Brithday:{3}", student.NO, student.Name, student.Age, student.Brithday.ToString("yyyy-MM-dd"));
Output
PS C:\Users\admin\source\repos\LHZ.FastJson\LHZ.FastJson.Test> dotnet run
NO:1,Name:lhz,Age:18,Brithday:2000-1-1
Camel-Case Configuration
By default, property names are serialized as-is (PascalCase). You can enable camelCase naming globally through JsonConvertConfig.UseCamelCase:
- During serialization, property names are converted to camelCase (e.g.
UserName→userName); - During deserialization, camelCase property names are matched automatically;
- Properties marked with the
[JsonProperty("xxx")]attribute always keep the explicitly configured name; - When the configuration changes, the compiled serialization/deserialization expression caches are invalidated automatically and recompiled.
Example
public class UserInfo
{
public string UserName { get; set; }
public int UserAge { get; set; }
}
JsonConvertConfig.UseCamelCase = true;
// Serialization: property names are converted to camelCase
string jsonStr = JsonConvert.Serialize(new UserInfo { UserName = "lhz", UserAge = 18 });
// Output: {"userName":"lhz","userAge":18}
// Deserialization: camelCase property names are matched automatically
UserInfo user = JsonConvert.Deserialize<UserInfo>("{\"userName\":\"lhz\",\"userAge\":18}");
JsonConvertConfig.UseCamelCase = false; // Restore the default
Building JSON Trees Programmatically
In addition to parsing JSON from strings, you can construct JSON trees directly using the JsonContent, JsonArray, JsonString, JsonNumber, JsonBoolean, and JsonNull classes:
//Object
var jsonContent = new JsonContent();
//Add String
jsonContent.AddJsonProperty("Name", new JsonString("LHZ.FastJson"));
//Add Number
jsonContent.AddJsonProperty("Size", new JsonNumber(1024));
//Add Boolean
jsonContent.AddJsonProperty("IsRelease", JsonBoolean.True);
//Add Null
jsonContent.AddJsonProperty("Exat", JsonNull.Null);
//Add Array
var jsonVersionArray = new JsonArray();
jsonVersionArray.AddJsonObject(new JsonString("2.0.0"));
jsonVersionArray.AddJsonObject(new JsonString("1.8.5"));
jsonVersionArray.AddJsonObject(new JsonString("1.8.4"));
jsonVersionArray.AddJsonObject(new JsonString("1.8.3"));
jsonContent.AddJsonProperty("Versions", jsonVersionArray);
//To Json String
var json = jsonContent.ToString();
OutPut
{"Name":"LHZ.FastJson","Size":1024,"IsRelease":true,"Exat":null,"Versions":["2.0.0","1.8.5","1.8.4","1.8.3"]}
JSON Parsing with JsonReader
JsonReader parses a JSON string into an IJsonObject tree that you can traverse dynamically.
Basic Parsing
using LHZ.FastJson;
string json = @"{""name"":""Alice"",""age"":25,""items"":[1,2,3]}";
var reader = new JsonReader(json);
IJsonObject obj = reader.JsonRead();
// Access parsed data
Console.WriteLine(obj["name"].Value); // Alice
Console.WriteLine(obj["age"].Value); // 25
Console.WriteLine(obj["items"][0].Value); // 1
Validate JSON
string json = @"{""key"":""value""}";
var reader = new JsonReader(json);
bool isValid = reader.IsValidJson; // true
string invalidJson = @"{""key"":}";
var reader2 = new JsonReader(invalidJson);
bool isValid2 = reader2.IsValidJson; // false
Static Validation
bool isJson = JsonReader.IsJsonString(jsonString, out Exception exception);
if (!isJson)
{
Console.WriteLine($"Invalid JSON: {exception.Message}");
}
Parsed JSON Type Tree
| JSON Value | IJsonObject Type |
.Value Type |
|---|---|---|
{"a":1} |
JsonContent |
Dictionary<JsonPropertyName, IJsonObject> |
[1,2] |
JsonArray |
List<IJsonObject> |
"text" |
JsonString |
string |
123 |
JsonNumber |
IConvertible (StringView) |
true / false |
JsonBoolean |
bool |
null |
JsonNull |
null |
Serialization Performance
LHZ.FastJson has been re-architected with a highly optimized serialization engine. The table below compares serialization performance across LHZ.FastJson, Newtonsoft.Json, and System.Text.Json:
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1706 (21H2)
Intel Core i7-9700K CPU 3.60GHz (Coffee Lake), 1 CPU, 8 logical and 8 physical cores
.NET SDK=6.0.201
[Host] : .NET 6.0.3 (6.0.322.12309), X64 RyuJIT
DefaultJob : .NET 6.0.3 (6.0.322.12309), X64 RyuJIT
| Method | Mean | Error | StdDev |
|---|---|---|---|
| LHZ.FastJson | 7.014 μs | 0.0298 μs | 0.0279 μs |
| Newtonsoft.Json | 18.943 μs | 0.1786 μs | 0.1671 μs |
| System.Text.Json | 10.410 μs | 0.0499 μs | 0.0467 μs |
Deserialization Performance
LHZ.FastJson has also been re-architected for deserialization, achieving nearly 2x performance improvement over versions prior to 1.6.0:
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1889 (21H2)
Intel Core i7-9700K CPU 3.60GHz (Coffee Lake), 1 CPU, 8 logical and 8 physical cores
.NET SDK=6.0.302
[Host] : .NET 6.0.7 (6.0.722.32202), X64 RyuJIT
DefaultJob : .NET 6.0.7 (6.0.722.32202), X64 RyuJIT
| Method | Mean | Error | StdDev |
|---|---|---|---|
| LHZFastJson v1.6.0 | 43.91 ms | 0.181 ms | 0.170 ms |
| LHZFastJson v1.5.2 | 85.18 ms | 0.301 ms | 0.282 ms |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.1-pre | 103 | 8/16/2026 |
| 2.0.0 | 98 | 8/16/2026 |
| 1.9.1 | 111 | 8/4/2026 |
| 1.9.0 | 127 | 7/11/2026 |
| 1.8.5 | 129 | 6/29/2026 |
| 1.8.4 | 121 | 6/24/2026 |
| 1.8.3 | 117 | 6/24/2026 |
| 1.8.2 | 124 | 6/23/2026 |
| 1.8.1 | 111 | 6/15/2026 |
| 1.7.2 | 6,178 | 9/27/2024 |
| 1.7.1 | 539 | 9/22/2024 |
| 1.6.0 | 998 | 8/20/2022 |
| 1.5.2 | 948 | 6/13/2022 |
| 1.5.1 | 971 | 6/12/2022 |
| 1.5.0 | 957 | 6/12/2022 |
| 1.4.2 | 968 | 8/19/2021 |
| 1.4.0 | 905 | 8/9/2021 |
| 1.3.6 | 945 | 6/7/2021 |
| 1.3.4 | 1,059 | 9/15/2020 |
| 1.3.3 | 1,022 | 8/11/2020 |
2.0.1-pre:新增 Camel-Case 命名配置(JsonConvertConfig.UseCamelCase)。