JsonNode in C#
JSON you explore rather than map onto a type.
using System.Text.Json.Nodes;
var doc = JsonNode.Parse("""
{"user": {"name": "ada", "roles": ["admin", "dev"]}}
""");
// nodes are for JSON you explore rather than map onto a type
Console.WriteLine((string)doc["user"]["name"]);
Console.WriteLine(doc["user"]["roles"][1]);
doc["user"]["active"] = true;
Console.WriteLine(doc.ToJsonString());
How it works
JsonNode.Parsebuilds a navigable tree from text.- Indexers walk objects and arrays; casts read the leaves.
- Nodes are mutable: patch a field and serialize back out.
Keywords and builtins used here
stringtrueusingvar
The run, in numbers
- Lines
- 12
- Characters to type
- 343
- Tokens
- 85
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 60 seconds.
Step 3 of 3 in JSON, step 6 of 17 in The .NET library.