landon-codes.JsonStorage 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package landon-codes.JsonStorage --version 1.1.1
                    
NuGet\Install-Package landon-codes.JsonStorage -Version 1.1.1
                    
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="landon-codes.JsonStorage" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="landon-codes.JsonStorage" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="landon-codes.JsonStorage" />
                    
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 landon-codes.JsonStorage --version 1.1.1
                    
#r "nuget: landon-codes.JsonStorage, 1.1.1"
                    
#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 landon-codes.JsonStorage@1.1.1
                    
#: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=landon-codes.JsonStorage&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=landon-codes.JsonStorage&version=1.1.1
                    
Install as a Cake Tool

JsonStorage

A simple C# library for managing JSON-based key-value storage in .NET applications.

Description

JsonStorage provides an easy-to-use interface for storing and retrieving data in JSON files. It allows you to persist application data, configuration settings, or any key-value pairs to disk using JSON format.

Features

  • Simple key-value storage API
  • Automatic JSON file creation and management
  • Load and save operations
  • Bulk key-value operations
  • File existence checking
  • Clear storage functionality

Installation

Manual Installation

  1. Clone or download this repository
  2. Add the JsonStorage.csproj to your solution
  3. Reference the project in your application

Binary Installation

  1. Download the Nuget package file from the GitHub repository's release page
  2. Add a reference to the installed Nuget package
  3. Reference the project in your application

CLI Installation

  1. Open a CLI terminal
  2. Navigate to your project directory
  3. Run dotnet package add landon-codes.JsonStorage
  4. Reference the project in your application

Usage

Basic Usage

using JsonStorage;

// Create a new storage instance
Storage storage = new Storage("data.json");

// Load existing data or create new file
storage.Load();

// Set some values
storage.storageObject["name"] = "John Doe";
storage.storageObject["age"] = 30;
storage.storageObject["isActive"] = true;

// Save to file
storage.Save();

Bulk Operations

// Define multiple keys and values at once
dynamic[] keys = { "setting1", "setting2", "setting3" };
dynamic?[] values = { "value1", 42, true };

storage.QuickDefine(keys, values);
storage.Save();

Retrieving Data

// Load data from file
storage.Load();

// Access values
string name = storage.storageObject["name"];
int age = storage.storageObject["age"];
bool isActive = storage.storageObject["isActive"];

Getting All Keys

dynamic[] keys = storage.GetKeys();
foreach (var key in keys)
{
    Console.WriteLine($"Key: {key}, Value: {storage.storageObject[key]}");
}

Clearing Storage

// Clear all data
storage.Clear();

// Clear and save immediately
storage.Clear(save: true);

API Reference

Storage Class

Constructor
  • Storage(string filePath) - Creates a new storage instance with the specified file path
Methods
  • Check() - Ensures the storage file exists, creates an empty JSON object if it doesn't
  • Load() - Loads data from the JSON file into memory
  • Save() - Saves the current storage object to the JSON file
  • QuickDefine(dynamic[] keys, dynamic?[] values) - Sets multiple key-value pairs at once
  • GetKeys() - Returns an array of all keys in the storage
  • Clear(bool save = false) - Removes all data from storage, optionally saves immediately

Note - Load and Save operations automatically run the Check() function automatically.

Properties
  • storageObject - Dictionary containing the key-value data

Requirements

  • .NET 9.0 or later
  • System.Text.Json (included in .NET Core/.NET 5+)

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Authors

landon-codes and contributors

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.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
3.0.0 95 8/31/2026
2.0.0 127 4/4/2026
1.1.1 114 3/27/2026