​​Convert an Object to a UTF-8 String



Serialization to an utf-8 byte array is a bit faster than the string method. This is because the bytes of utf-8 is not required to convert to strings of utf-16.



The following example shows the conversion of an object to a minified JSON string using JsonSerializer.SerializeToUtf8Bytes method.



Thus, you can convert C# object to JSON in different ways for different versions using JsonConvert.Serialize() method in .NET 4.x and .NET 5.