public static ToJson ( Document document, bool prettyPrint ) : string | ||
document | Document | |
prettyPrint | bool | |
return | string |
public static string ToJson(Document document, bool prettyPrint)
{
var sb = new StringBuilder();
var writer = new JsonWriter(sb);
writer.PrettyPrint = prettyPrint;
WriteJson(document, writer, DynamoDBEntryConversion.V2);
// Trim everything before the first '{' character
var jsonIndex = FirstIndex(sb, '{');
if (jsonIndex > 0)
sb.Remove(0, jsonIndex);
var jsonText = sb.ToString();
return jsonText;
}
/// <summary> /// <para> /// Converts the current Document into a matching pretty JSON string. /// </para> /// <para> /// DynamoDB types are a superset of JSON types, thus the following DynamoDB cannot /// be properly represented as JSON data: /// PrimitiveList (SS, NS, BS types) - these sets will be converted to JSON arrays /// Binary Primitive (B type) - binary data will be converted to Base64 strings /// </para> /// <para> /// If the resultant JSON is passed to Document.FromJson, the binary values will be /// treated as Base64 strings. Invoke Document.DecodeBase64Attributes to decode these /// strings into binary data. /// </para> /// </summary> /// <returns>JSON string corresponding to the current Document.</returns> public string ToJsonPretty() { return(JsonUtils.ToJson(this, prettyPrint: true)); }