public static void Main()
Console.WriteLine("Hello World");
SomeObject obj = new SomeObject{
Property1 = "value of property 1",
Property2 = "value of property 2"
string s = obj.ToJsonString();
Console.WriteLine($"Json body: {s}");
SomeObject obj2 = s.ToObject<SomeObject>();
Console.WriteLine($"obj2.Property1 = {obj2.Property1}");
public static class Extensions{
public static string ToJsonString<T>(this T obj){
return JsonSerializer.Serialize(obj);
public static T ToObject<T>(this string objectStr){
return JsonSerializer.Deserialize<T>(objectStr);
public string Property1 { get; set; }
public string Property2 { get; set; }