ToolBX.FileGuy.Json
3.0.0
dotnet add package ToolBX.FileGuy.Json --version 3.0.0
NuGet\Install-Package ToolBX.FileGuy.Json -Version 3.0.0
<PackageReference Include="ToolBX.FileGuy.Json" Version="3.0.0" />
paket add ToolBX.FileGuy.Json --version 3.0.0
#r "nuget: ToolBX.FileGuy.Json, 3.0.0"
// Install ToolBX.FileGuy.Json as a Cake Addin #addin nuget:?package=ToolBX.FileGuy.Json&version=3.0.0 // Install ToolBX.FileGuy.Json as a Cake Tool #tool nuget:?package=ToolBX.FileGuy.Json&version=3.0.0
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 | Versions 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. |
-
net8.0
- ToolBX.AutoInject (>= 3.0.0)
- ToolBX.FileGuy (>= 3.0.0)
- ToolBX.NetAbstractions (>= 3.0.0)
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 |
---|---|---|
3.0.0 | 110 | 9/27/2024 |
3.0.0-beta1 | 79 | 9/23/2024 |
2.2.0 | 188 | 1/13/2024 |
2.2.0-beta2 | 100 | 1/11/2024 |
2.2.0-beta1 | 123 | 1/7/2024 |
2.0.2 | 176 | 6/19/2023 |
2.0.1 | 172 | 4/27/2023 |
2.0.0 | 375 | 11/12/2022 |
2.0.0-beta1 | 146 | 10/7/2022 |
1.0.1 | 417 | 10/7/2022 |
1.0.0 | 414 | 5/16/2022 |