Complete the code to read a JSON file into a string.
string jsonString = File.[1]("data.json");
The File.ReadAllText method reads the entire content of a file as a string, which is perfect for reading JSON files.
Complete the code to deserialize JSON string into an object of type Person.
Person person = JsonSerializer.[1]<Person>(jsonString);The JsonSerializer.Deserialize<T> method converts a JSON string into an object of type T.
Fix the error in the code to serialize an object to JSON string.
string jsonString = JsonSerializer.[1](person);The Serialize method converts an object into a JSON string.
Fill both blanks to write a JSON string to a file asynchronously.
await File.[1]Async("output.json", jsonString[2]);
The WriteAllTextAsync method writes text to a file asynchronously. The second blank is a cancellation token parameter, which can be CancellationToken.None if no cancellation is needed.
Fill all three blanks to create a dictionary from JSON and filter keys with length > 3.
var filtered = jsonDict.Where(kv => kv.Key.[1] > 3).ToDictionary(kv => kv.[2], kv => kv.[3]);
We use Length to get the length of the key string, then select Key and Value to build the filtered dictionary.