ToolBX.FileGuy.Json 2.2.0

dotnet add package ToolBX.FileGuy.Json --version 2.2.0
NuGet\Install-Package ToolBX.FileGuy.Json -Version 2.2.0
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="ToolBX.FileGuy.Json" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.FileGuy.Json --version 2.2.0
#r "nuget: ToolBX.FileGuy.Json, 2.2.0"
#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.
// Install ToolBX.FileGuy.Json as a Cake Addin
#addin nuget:?package=ToolBX.FileGuy.Json&version=2.2.0

// Install ToolBX.FileGuy.Json as a Cake Tool
#tool nuget:?package=ToolBX.FileGuy.Json&version=2.2.0

FileGuy

FileGuy.Json

FileGuy.Json is a simple library that allows you to read and write json to and from files in a simple way using the System.Text.Json library.

FileSerializer

A service that allows you to read and write json to and from files directly.

Usage

private readonly FileSerializer _fileSerializer;

public MyClass(FileSerializer fileSerializer)
{
	_fileSerializer = fileSerializer;
}

public void WriteJsonToFile()
{
	var myObject = new MyObject();
	_fileSerializer.Serialize(myObject, "myObject.json");
}

A FileSerializerOptions object can also be passed which contains a System.Text.Json.JsonSerializerOptions object. This allows you to configure the serialization process.

var options = new FileSerializerOptions
{
	Serializer = new JsonSerializerOptions
	{
		PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
		WriteIndented = true
	}
};

_fileSerializer.Serialize(myObject, "myObject.json", options);

The Deserialize method works as you would expect.

private readonly FileSerializer _fileSerializer;

public MyClass(FileSerializer fileSerializer)
{
	_fileSerializer = fileSerializer;
}

public void ReadJsonFromFile()
{
	var myObject = _fileSerializer.Deserialize<MyObject>("myObject.json", new FileSerializerOptions
	{
		Serializer = new JsonSerializerOptions
		{
			PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
			WriteIndented = true
		}
	});
}

Compression/Decompression

The FileSerializer class also has methods for compressing and decompressing json files in the same way that FileGuy.FileSaver and FileGuy.FileLoader already do.

private readonly FileSerializer _fileSerializer;

public MyClass(FileSerializer fileSerializer)
{
	_fileSerializer = fileSerializer;
}

public void CompressJsonFile()
{
	_fileSerializer.Serialize("myObject.json", new FileSerializerOptions
	{
		//Uses NoCompression by default
		CompressionLevel = CompressionLevel.Optimal
	});
}

public void DecompressJsonFile()
{
	var myObject = _fileSerializer.Decompress<MyObject>("myObject.json");
	...
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.0 151 1/13/2024
2.2.0-beta2 69 1/11/2024
2.2.0-beta1 80 1/7/2024
2.0.2 145 6/19/2023
2.0.1 145 4/27/2023
2.0.0 339 11/12/2022
2.0.0-beta1 121 10/7/2022
1.0.1 384 10/7/2022
1.0.0 381 5/16/2022