using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text.Json.Serialization;
public int Id { get; set; }
public string Name { get; set; }
public string ContactPhone { get; set; }
public IEnumerable<MedicalRecord> MedicalRecords { get; set; }
internal class MedicalRecord {
public int Id { get; set; }
public string Name { get; set; }
public DateTime RecordDate { get; set; }
public IEnumerable<DiseaseLog> DiseaseLogs{ get; set; }
internal class DiseaseLog {
public int Id { get; set; }
public string Name { get; set; }
public DateTime LogDate { get; set; }
public static void Test()
var students = new List<Student> {
ContactPhone = "123-122-3311",
MedicalRecords = new List<MedicalRecord>()
Name = "Medial record 101011",
RecordDate = new DateTime(2021, 12, 31),
DiseaseLogs = new List<DiseaseLog>()
Name = "Patient Log 19292",
LogDate = new DateTime(2020, 1, 31),
Name = "Patient Log 2911w",
LogDate = new DateTime(2020, 3, 31),
var dynamicJson = @"{""roomid"":1,""roomcode"":""Code001"",""students"":[1],""contentdata"":""say hello"",""footerdata"":""cookie policy""}";
var root = JsonSerializer.Deserialize<OrderedDictionary>(dynamicJson);
root["students"] = students;
var modifyJson = JsonSerializer.Serialize(root, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true });
Console.WriteLine(modifyJson);
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version);
Console.WriteLine("System.Text.Json version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");