Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the counterpart to JObject.FromObject in System.Text.Json

With Newtonsoft Json you can convert an object to a JObject by calling JObject.FromObject(object).

Is there a counterpart in System.Text.Json to get a JsonDocument from an object?

like image 722
Kirill Rakhman Avatar asked Mar 06 '20 13:03

Kirill Rakhman


1 Answers

There is an open issue for it.

But now there is no such methods. You can try

 using (JsonDocument document = JsonDocument.Parse(JsonSerializer.Serialize(object)))
 {
    ...
 }

One more issue

like image 137
Roman Marusyk Avatar answered Oct 03 '22 20:10

Roman Marusyk