using System.Collections.Generic;
Dictionary<string, Dictionary<string, Dictionary<string, string>>> allMediaSources = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
string jsonString = "{\"ArcadeDB\":{\"mame\":{\"ImageSource\":\"Screenshot\",\"LogoSource\":\"Clear Logo\",\"BoxSource\":\"Cabinet\",\"VideoSource\":\"Standard\"},\"mastersystem\":{\"ImageSource\":\"Title\",\"LogoSource\":\"Clear Logo\",\"BoxSource\":\"Cabinet\",\"VideoSource\":\"Standard\"}},\"EmuMovies\":{\"mame\":{\"ImageSource\":\"Screenshot\",\"LogoSource\":\"Clear Logo\",\"BoxSource\":\"Box 2D\",\"CartridgeSource\":\"Cartridge\",\"VideoSource\":\"Standard\"},\"mastersystem\":{\"ImageSource\":\"Screenshot\",\"LogoSource\":\"Clear Logo\",\"BoxSource\":\"Box 2D\",\"CartridgeSource\":\"Cartridge\",\"VideoSource\":\"Standard\"}},\"ScreenScraper\":{\"mame\":{\"ImageSource\":\"Screenshot\",\"LogoSource\":\"Clear Logo\",\"BoxSource\":\"Box 2D\",\"VideoSource\":\"Standard\"},\"mastersystem\":{\"ImageSource\":\"Screenshot\",\"LogoSource\":\"Clear Logo\",\"BoxSource\":\"Box 2D\",\"VideoSource\":\"Standard\"}}}";
string scraper = "scraper";
string system = "system";
Dictionary<string, string> mediaSources = new(){ { "TEST KEY", "TEST VALUE" }};
if (!string.IsNullOrEmpty(jsonString))
allMediaSources = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(jsonString)
?? new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
allMediaSources = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
if (!allMediaSources.ContainsKey(scraper))
allMediaSources[scraper] = [];
var nestedDictionary = allMediaSources[scraper];
if (!nestedDictionary.ContainsKey(system))
nestedDictionary.Add(system, mediaSources);
nestedDictionary[system] = mediaSources;
JsonSerializerOptions opts = new(){WriteIndented = true};
newJsonString = JsonSerializer.Serialize(allMediaSources, opts);
Console.WriteLine(newJsonString);