typestar

JsonConvert in C#

The serializer that carried .NET JSON for a decade.

using Newtonsoft.Json;

var release = new Release("1.4.0", true);
Console.WriteLine(JsonConvert.SerializeObject(release));

var json = """{"Version": "2.0.0", "Stable": false}""";
var parsed = JsonConvert.DeserializeObject<Release>(json);
Console.WriteLine($"{parsed.Version} stable: {parsed.Stable}");

record Release(string Version, bool Stable);

How it works

  1. SerializeObject handles records without configuration.
  2. DeserializeObject<T> maps by property name onto the constructor.
  3. Newtonsoft remains everywhere older APIs and SDKs live.

Keywords and builtins used here

The run, in numbers

Lines
10
Characters to type
348
Tokens
70
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 47 seconds.

Type this snippet

Step 2 of 3 in JSON with Newtonsoft, step 2 of 16 in The open ecosystem.

← Previous Next →