Sometimes I find I want to dump an object that I see in debugging for further analysis, testing or just to get a feel for the shape of some data. To do this I stop at a location in the debugger where the data is visible grab a copy of the required variable and then switch to the VS Immediate Window.
In Immediate window I can dump a variables contents to a json file by typing in the following C#:
File.WriteAllText(@"c:\Somewhere\delme.json", Newtonsoft.Json.JsonConvert.SerializeObject(myobject, Formatting.Indented));
Alternatively use System.Text.Json
File.WriteAllText(@"c:\somewhere\delme.json", System.Text.Json.JsonSerializer.Serialize(myobject, new System.Text.Json.JsonSerializerOptions() { WriteIndented = true }));