Search code examples
c#.net-coresystem.text.json

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?


Solution

  • 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