using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
var fileName = "Question77614687.json";
File.WriteAllText(fileName, json);
var key = "KeyICareAbout";
using var stream = File.OpenRead(fileName);
using var textReader = new StreamReader(stream, Encoding.UTF8);
using var reader = new JsonTextReader(textReader);
var list = new List<JToken>();
if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == key)
list.Add(JToken.Load(reader.ReadToContentAndAssert()));
Console.WriteLine(JsonConvert.SerializeObject(list, Formatting.Indented));
Assert.That(list.Select(i => i.ToString()).SequenceEqual(new [] { "C", "G" }));
public static partial class JsonExtensions
public static JsonReader AssertTokenType(this JsonReader reader, JsonToken tokenType) =>
reader.TokenType == tokenType ? reader : throw new JsonSerializationException(string.Format("Unexpected token {0}, expected {1}", reader.TokenType, tokenType));
public static JsonReader ReadToContentAndAssert(this JsonReader reader) =>
reader.ReadAndAssert().MoveToContentAndAssert();
public static JsonReader MoveToContentAndAssert(this JsonReader reader)
ArgumentNullException.ThrowIfNull(reader);
if (reader.TokenType == JsonToken.None)
while (reader.TokenType == JsonToken.Comment)
public static JsonReader ReadAndAssert(this JsonReader reader)
ArgumentNullException.ThrowIfNull(reader);
throw new JsonReaderException("Unexpected end of JSON stream.");
public static void Main()
Console.WriteLine("Environment version: {0} ({1}), {2}", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version, Environment.OSVersion);
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Namespace, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");