Convert a C# Object to JSON Using System.Text.JSON and Newtonsoft.JSON with Different Options

preview_player
Показать описание

In this video, I’m gonna show you how to convert a C# object into a JSON string and also, how to control different aspects of the serialization process. You’ll see how to generate pretty JSON strings, ignore properties and null values, change the naming convention, control DateTime formatting, and also how to avoid circular reference while doing serialization. So as you can see a lot of different features that we as developers use every day. For this, I will use both the System.Text.JSON and Newtonsoft JSON libraries.

FOLLOW US ON SOCIAL MEDIA!
Рекомендации по теме
Комментарии
Автор

Thank you all for watching and for your support.

CodeMaze
Автор

Great tutorial for JSON serialization. Thank you!

FearGod
Автор

Thx!
If its not hard for you add pls benchmarks in to the end of the video.

I-PixALbI-I
Автор

Thank you for this video. You spelled Newtonsoft.JSON as "Newtonsont.JSON"

nelsonrivers
Автор

ty but i am having a big trouble. My json has characters like ç, ê, í, and all those chars are been replaced by starng code: \u00E7, \u00F3, \u00E9 and all others.
How i replaced for the right character, please?

I used: var jsonparsed = JsonDocument.Parse(json, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip });
string json2 = ToJsonString(jsonparsed);

public static string ToJsonString(this JsonDocument jdoc)
{
using (var stream = new MemoryStream())
{
Utf8JsonWriter writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
jdoc.WriteTo(writer);
writer.Flush();
return
}
}

Thanks!!!!

diego-vwin