Programming foundations

Stage 6 · Lesson 3 of 8

Files and JSON with System.Text.Json

Build and ship your first projects

.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 repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?