landon-codes.JsonStorage
1.1.1
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
<PackageReference Include="landon-codes.JsonStorage" Version="1.1.1" />
<PackageVersion Include="landon-codes.JsonStorage" Version="1.1.1" />
<PackageReference Include="landon-codes.JsonStorage" />
paket add landon-codes.JsonStorage --version 1.1.1
#r "nuget: landon-codes.JsonStorage, 1.1.1"
#:package landon-codes.JsonStorage@1.1.1
#addin nuget:?package=landon-codes.JsonStorage&version=1.1.1
#tool nuget:?package=landon-codes.JsonStorage&version=1.1.1
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
- Clone or download this repository
- Add the
JsonStorage.csprojto your solution - Reference the project in your application
Binary Installation
- Download the Nuget package file from the GitHub repository's release page
- Add a reference to the installed Nuget package
- Reference the project in your application
CLI Installation
- Open a CLI terminal
- Navigate to your project directory
- Run
dotnet package add landon-codes.JsonStorage - 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'tLoad()- Loads data from the JSON file into memorySave()- Saves the current storage object to the JSON fileQuickDefine(dynamic[] keys, dynamic?[] values)- Sets multiple key-value pairs at onceGetKeys()- Returns an array of all keys in the storageClear(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 | Versions 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. |
-
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.