NetTools.Serialization.Json 1.1.41

dotnet add package NetTools.Serialization.Json --version 1.1.41
                    
NuGet\Install-Package NetTools.Serialization.Json -Version 1.1.41
                    
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="NetTools.Serialization.Json" Version="1.1.41" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetTools.Serialization.Json" Version="1.1.41" />
                    
Directory.Packages.props
<PackageReference Include="NetTools.Serialization.Json" />
                    
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 NetTools.Serialization.Json --version 1.1.41
                    
#r "nuget: NetTools.Serialization.Json, 1.1.41"
                    
#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 NetTools.Serialization.Json@1.1.41
                    
#: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=NetTools.Serialization.Json&version=1.1.41
                    
Install as a Cake Addin
#tool nuget:?package=NetTools.Serialization.Json&version=1.1.41
                    
Install as a Cake Tool

NetTools.Serialization.Json

NetTools.Serialization.Json is a lightweight yet powerful .NET Standard 2.1 class library designed for JSON serialization and deserialization. It offers an intuitive API for working with JSON in your .NET applications without the overhead of larger libraries like Newtonsoft's JSON.Net.

This library evolved from the "Really simple JSON parser in ~300 lines" and has grown into a robust solution for developers seeking simplicity, speed, and extensibility. NetTools.Serialization.Json is based on factory and injection design patterns, enabling seamless support for various object types, including interface types, which are traditionally challenging to deserialize via reflection.

Features

  • Minimal Design: Focused and efficient, with no unnecessary complexity or bloated dependencies.
  • Powerful Deserialization: Supports deserialization to interface types using the KnownObject attribute or custom serialization factories.
  • Flexible Configuration: Options for including private fields, handling broken JSON, and customizing serialization.
  • Convenient Extensions: Extension methods for serializing and deserializing JSON with dictionaries, lists, and dynamic objects.
  • Prettify and Minify JSON: Easily format JSON for readability or compress it for efficiency.
  • Easy Integration: Built with simplicity in mind, allowing quick adoption into your project.

Getting Started

Installation

To use NetTools.Serialization.Json in your project, simply add the library via NuGet Package Manager:

Install-Package NetTools.Serialization.Json

Quick Examples

Here's a basic demonstration of how to use NetTools.Serialization.Json for serialization and deserialization: Serialize an Object to JSON

using NetTools.Serialization.Json;

var person = new 
{
    Name = "John",
    Age = 30,
    IsDeveloper = true
};

string jsonString = person.ToJson();
Console.WriteLine(jsonString);

Deserialize JSON to an Object

using NetTools.Serialization.Json;

string jsonString = "{\"Name\":\"John\",\"Age\":30,\"IsDeveloper\":true}";

var deserializedPerson = jsonString.FromJson<dynamic>();
Console.WriteLine($"Name: {deserializedPerson.Name}, Age: {deserializedPerson.Age}, Developer: {deserializedPerson.IsDeveloper}");

Additional Examples

Beautify JSON

string uglyJson = "{\"Name\":\"John\",\"Age\":30,\"IsDeveloper\":true}";
string prettyJson = uglyJson.BeautifyJson();
Console.WriteLine(prettyJson);

Minify JSON

string formattedJson = "{\n  \"Name\": \"John\",\n  \"Age\": 30,\n  \"IsDeveloper\": true\n}";
string minifiedJson = formattedJson.MinifyJson();
Console.WriteLine(minifiedJson);

Advanced Usage: Deserializing to Interfaces

NetTools.Serialization.Json simplifies the deserialization of interface types. Use the KnownObject attribute or configure a custom IStringSerializer via SerializationFactory if you don't have access to the source to add attributes to enable instance creation.

using NetTools.Serialization.Json;

[KnownObject(typeof(Person))]
public interface IPerson
{
    string Name { get; set; }
    int Age { get; set; }
}

public class Person : IPerson
{
    public string Name { get; set; }
    public int Age { get; set; }
}

string jsonString = "{\"Name\":\"John\",\"Age\":30}";
var person = jsonString.FromJson<IPerson>();
Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");

Contributing

We welcome contributions! To get involved:

  1. Fork NetTools.Serialization.Json, make improvements, and submit a pull request.
  2. Code will be reviewed upon submission.
  3. Join discussions via the issues board.

License

NetTools.Serialization.Json is licensed under the MIT License, allowing unrestricted use, modification, and distribution. If you use NetTools.Serialization.Json in your own project, we’d love to hear about your experience, and possibly feature you on our website!

Full documentation coming soon!

NetModules Foundation

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on NetTools.Serialization.Json:

Package Downloads
NetModules.Settings.LocalSettings

A basic settings module that loads local configuration files into memory. This module handles the NetModules.Events.GetSettingEvent event. Configuration files must be JSON object formatted with a filename that starts with the module's namespace, followed by the module's name, and ending with a .json extension.

NetModules.Logging.LocalLogging

A basic logging module. This module writes any NetModules.LoggingEvent data to the console output where available and also writes logs to a file in the Module.WorkingDirectory path using log rotation.

NetModules.Cache.MemoryCache

A basic cache module that uses an in-memory mechanism to store event output to a cache, using the event name, input, and optional metadata as a storage and lookup identifier.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.41 142 5/29/2025
1.1.40 223 5/14/2025
1.1.39 253 5/1/2025