diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs
index 93bf51e251bf0..5f7ef94297fbc 100644
--- a/csharp/src/Google.Protobuf/JsonFormatter.cs
+++ b/csharp/src/Google.Protobuf/JsonFormatter.cs
@@ -145,11 +145,26 @@ public JsonFormatter(Settings settings)
/// Formats the specified message as JSON.
///
/// The message to format.
+ /// This method delegates to Format(IMessage, int) with indentationLevel = 0.
/// The formatted message.
- public string Format(IMessage message)
+ public string Format(IMessage message) => Format(message, indentationLevel: 0);
+
+ ///
+ /// Formats the specified message as JSON.
+ ///
+ /// The message to format.
+ /// Indentation level to start at.
+ /// To keep consistent indentation when embedding a message inside another JSON string, set . E.g:
+ ///
+ /// var response = $@"{{
+ /// ""data"": { Format(message, indentationLevel: 1) }
+ /// }}"
+ ///
+ /// The formatted message.
+ public string Format(IMessage message, int indentationLevel)
{
var writer = new StringWriter();
- Format(message, writer);
+ Format(message, writer, indentationLevel);
return writer.ToString();
}
@@ -168,6 +183,7 @@ public string Format(IMessage message)
/// The message to format.
/// The TextWriter to write the formatted message to.
/// Indentation level to start at.
+ /// To keep consistent indentation when embedding a message inside another JSON string, set .
public void Format(IMessage message, TextWriter writer, int indentationLevel)
{
ProtoPreconditions.CheckNotNull(message, nameof(message));