Stage 6 · Lesson 3 of 8
Files and JSON with System.Text.Json
.NET includes , which handles : turning objects into JSON text and back. JsonSerializer.Deserialize<List<Entry>>(json) turns JSON text into your own types, and JsonSerializer.Serialize(entries, new JsonSerializerOptions { WriteIndented = true }) writes them back.
make good for this. Property names are matched case-sensitively by default. So "amount" in the file does not fill Amount unless you set PropertyNameCaseInsensitive or a naming policy.
That is a very common "why is everything zero?" bug. Deserialize can return null, which the nullable warnings will point out. uses File.ReadAllTextAsync.
Handle FileNotFoundException and JsonException, and keep loading and saving in one class.
A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with
- GitHub repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch