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
SerializeObjecthandles records without configuration.DeserializeObject<T>maps by property name onto the constructor.- Newtonsoft remains everywhere older APIs and SDKs live.
Keywords and builtins used here
Releaseboolnewrecordstringtrueusingvar
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.
Step 2 of 3 in JSON with Newtonsoft, step 2 of 16 in The open ecosystem.