var options = new JsonSerializerOptions { WriteIndented = true }; string jsonString = JsonSerializer.Serialize(myObject, options);