Oakrey.Applications.Json.Abstractions 6.0.0

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

Oakrey.Applications.Json.Abstractions

A .NET 10 library that defines the IJsonService abstraction for JSON serialization and deserialization operations. It contains no implementation code, no logging, and no telemetry dependencies, making it the correct reference for libraries and application layers that need JSON access without coupling to a concrete implementation.

Main features

Method Description
LoadJson<T>(fileName) Deserializes a JSON file to T (synchronous)
LoadJsonAsync<T>(fileName, ct) Deserializes a JSON file to T (asynchronous, CancellationToken aware)
LoadObjectsFromJsonFilesAsync<T>(folder, extension, ct) Loads and deserializes all JSON files in a directory matching the given extension into a List<T>
SaveJson<T>(value, fileName) Serializes value to a JSON file (synchronous)
SaveJsonAsync<T>(value, fileName) Serializes value to a JSON file (fire-and-forget async)
SaveJsonFiles<TNamed>(jsons, folder, extension) Serializes a collection of IName items to individual files named after each item in the given directory

SaveJsonFiles requires TNamed to implement IName from Oakrey.Collections, which provides a Name property used as the file name.

Architecture

classDiagram
    class IJsonService {
        +LoadJson~T~(fileName) T
        +LoadJsonAsync~T~(fileName, ct) Task~T~
        +LoadObjectsFromJsonFilesAsync~T~(folder, extension, ct) Task~List~T~~
        +SaveJson~T~(value, fileName)
        +SaveJsonAsync~T~(value, fileName)
        +SaveJsonFiles~TNamed~(jsons, folder, extension)
    }

    class JsonService {
        <<Oakrey.Applications.Json>>
    }

    class IFileService {
        <<Oakrey.Applications.Files.Abstractions>>
    }

    IJsonService <|.. JsonService
    JsonService --> IFileService

The concrete implementation lives in the separate Oakrey.Applications.Json package. Consuming projects should reference only this abstractions package and register the implementation via the extension provided by Oakrey.Applications.Json.

Requirements

  • .NET 10 or later
  • Oakrey.Collections � provides the IName interface required by SaveJsonFiles

Installation

dotnet add package Oakrey.Applications.Json.Abstractions

To also include the concrete implementation:

dotnet add package Oakrey.Applications.Json

Example usage

Registering the service

// In your composition root, reference Oakrey.Applications.Json for the extension method.
services.AddJsonService();

Deserializing a single file

public sealed class ConfigLoader
{
    private readonly IJsonService _jsonService;

    public ConfigLoader(IJsonService jsonService)
    {
        _jsonService = jsonService;
    }

    public async Task<AppConfig> LoadAsync(string path, CancellationToken cancellationToken)
    {
        return await _jsonService.LoadJsonAsync<AppConfig>(path, cancellationToken);
    }
}

Loading all files from a directory

List<Profile> profiles = await _jsonService.LoadObjectsFromJsonFilesAsync<Profile>(
    folder: @"C:\Data\Profiles",
    extension: "json",
    cancellationToken: cancellationToken);

Saving a batch of named objects

// Profile implements IName, so each item is saved as "{profile.Name}.json".
_jsonService.SaveJsonFiles(profiles, folder: @"C:\Data\Profiles", extension: "json");

Development notes

  • This package contains only the IJsonService interface. No serializer, logger, or tracer code is included.
  • The concrete implementation (JsonService) is in Oakrey.Applications.Json. It uses System.Text.Json with stream-based I/O via IFileService, structured logging via Oakrey.Log, and OpenTelemetry activity spans via Oakrey.Telemetry.
  • Both packages share the Oakrey.Applications.Json root namespace.
  • The Oakrey.Collections dependency is required here because IName appears in the SaveJsonFiles contract on the interface itself.

License

MIT � Copyright � Oakrey 2016-present

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (3)

Showing the top 3 NuGet packages that depend on Oakrey.Applications.Json.Abstractions:

Package Downloads
Oakrey.Applications.Json

Provides IJsonService for stream-based JSON serialization and deserialization using System.Text.Json, with async CancellationToken support, batch directory load, IName-keyed batch save, and built-in logging and OpenTelemetry tracing via IFileService.

Oakrey.Applications.ControlObjects

A .NET WPF library for building interactive, validated control objects. Provides a base class hierarchy for reactive sending objects, enable/disable and timer-driven variants, cancelable async operations, device abstraction, multi-key gesture support, and observable collections with automatic JSON persistence.

Oakrey.Applications.Ohm.CAN

Service layer library for managing CAN bus hardware devices and channels. Provides device discovery, connection lifecycle management, reactive IObservable streams for received frames and status changes, per-channel transmit, USB hot-plug detection, and persistent JSON configuration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 117 5/22/2026
3.0.4 114 5/22/2026