blob: 812c81c01c2e06dcd30ac4fdfdfc60f0b39ad7ed (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
using System.Text.Encodings.Web;
using System.Text.Json;
namespace MatrixRoomUtils.Core.Extensions;
public static class ObjectExtensions {
public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false, bool unsafeContent = false) {
var jso = new JsonSerializerOptions();
if (indent) jso.WriteIndented = true;
if (ignoreNull) jso.IgnoreNullValues = true;
if (unsafeContent) jso.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
return JsonSerializer.Serialize(obj, jso);
}
}
|