MarcusMedina.IO.JsonFile
4.0.1
dotnet add package MarcusMedina.IO.JsonFile --version 4.0.1
NuGet\Install-Package MarcusMedina.IO.JsonFile -Version 4.0.1
<PackageReference Include="MarcusMedina.IO.JsonFile" Version="4.0.1" />
<PackageVersion Include="MarcusMedina.IO.JsonFile" Version="4.0.1" />
<PackageReference Include="MarcusMedina.IO.JsonFile" />
paket add MarcusMedina.IO.JsonFile --version 4.0.1
#r "nuget: MarcusMedina.IO.JsonFile, 4.0.1"
#:package MarcusMedina.IO.JsonFile@4.0.1
#addin nuget:?package=MarcusMedina.IO.JsonFile&version=4.0.1
#tool nuget:?package=MarcusMedina.IO.JsonFile&version=4.0.1
MarcusMedina.IO.JsonFile
Save and load any object as a JSON file — one class, zero boilerplate.
Back in 2009, while I was in my second year of studies myself and working as a supervisor for first-year students, I wrote the first version of this to show them what object-oriented programming was actually good for — not just theory about classes and encapsulation, but a real class that hides the messy plumbing behind a clean interface. It doubled as a lifesaver in their own coursework: a lot of them were writing small games at the time, and this gave them an easy way to save and reload progress without having to think about serialisation themselves.
In this case, I wanted the whole save/load story to disappear behind two lines of code, so the lesson stayed about OOP, not about JSON.
using MarcusMedina.IO.JsonFile;
var settings = new JsonFile<AppSettings>("settings");
settings.Data.Theme = "dark";
settings.Save();
// Next run — loads automatically in constructor
var settings = new JsonFile<AppSettings>("settings");
Console.WriteLine(settings.Data.Theme); // "dark"
Features
- Generic
JsonFile<T>— works with any serializable type - Auto-loads on construction, auto-saves on
Dispose() - Creates
.bakbackup before overwriting - Configurable suffix (default
.json) - Implicit conversion to
Tfor clean usage - Graceful handling of missing or corrupt files
Installation
dotnet add package MarcusMedina.IO.JsonFile
Quick Start
using MarcusMedina.IO.JsonFile;
// Works with any type — list, record, class
var log = new JsonFile<List<string>>("app-log");
log.Data ??= [];
log.Data.Add("Started");
log.Save();
// Implicit conversion
List<string> entries = log;
With using block (auto-save on exit):
using var config = new JsonFile<Config>("config");
config.Data ??= new Config();
config.Data.Debug = true;
// Save() called automatically when leaving the block
API
| Member | Description |
|---|---|
JsonFile<T>(string filename) |
Creates and loads from {filename}.json |
Data |
The deserialized object |
Filename |
File name without suffix |
Suffix |
File extension (default "json") |
Format |
JsonSerializerOptions for customizing serialization |
Load() |
Reloads from disk |
Save() |
Writes to disk, creates .bak backup |
Dispose() |
Calls Save() — use with using |
Migrating from MarcusMedina.JsonFileWrapper
Replace the using directive:
// Before
using MarcusMedina.JsonFileWrapper;
// After
using MarcusMedina.IO.JsonFile;
The JsonFile<T> class is identical — no other changes needed.
Package Integrity
All releases are signed with cosign (Sigstore keyless signing).
To verify a downloaded package, download both the .nupkg and its .sigstore.json bundle from the GitHub Release, then run:
cosign verify-blob <package.nupkg> \
--bundle <package.nupkg.sigstore.json> \
--certificate-identity-regexp "https://github.com/MarcusMedinaPro/.*/release.yml" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
Expected output: Verified OK
Built with Human + AI Collaboration
This library was written by Marcus Medina together with Claude Code (Anthropic) — not through "vibe coding" where you just describe and accept, but through genuine collaboration: planning together, reviewing each other's decisions, pushing back when something felt wrong, and iterating until the result felt right.
The goal was always to write code worth reading and code worth using — the kind a student can open, understand, and learn from, and the kind any programmer can drop into real, professional work without wanting to rewrite it from scratch. AI was a partner in that process, not a shortcut around it.
If you're curious about this way of working, the source code and git history are open. Every decision has a reason behind it.
Made for Curious Minds
This library was built with students in mind — not as a black box to copy and paste, but as a real-world example of how clean, purposeful code is written and shared.
Whether you're discovering C# for the first time, need a reliable helper for your school project, or are simply trying to fall in love with writing code — you're exactly who this was made for.
The source is open. Read it, fork it, break it, improve it. That's the whole point.
And if this library saved you an afternoon, or made something click that didn't before — that's everything.
Non-students are equally welcome. Good code doesn't care about your diploma.
⭐ If this helped you, consider starring the project on GitHub — it helps other students find it too.
💬 Have an idea, a feature request, or just want to say hi? Open an issue on GitHub — I'd love to hear from you.
License
MIT — see LICENSE
| Product | Versions 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. |
-
net10.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.