Skip to content

System.Text.Json support

JPVenson edited this page May 19, 2022 · 1 revision

Morestachio supports the direct access to the JsonDocument and JsonElement types. Using the Nuget Morestachio System.Text.Json nuget package, you can enable IValueConverter by calling the extension method WithSystemTextJsonValueResolver on any IParserOptionsBuilder like this:

var document = await ParserOptionsBuilder.New()
             .WithSystemTextJsonValueResolver()
             ...
             .BuildAndParseAsync();

The template can now access any Json document directly like this:

var jsonDocument = System.Text.Json.JsonDocument.Parse(jsonText);
document.CreateRenderer().RenderAndStringify(jsonDocument);