Skip to content

Instantly share code, notes, and snippets.

@terrajobst
Last active August 15, 2020 10:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrajobst/336da6ae0a327bef113c1325710164f0 to your computer and use it in GitHub Desktop.
Save terrajobst/336da6ae0a327bef113c1325710164f0 to your computer and use it in GitHub Desktop.
var options = new JsonWriterOptions
{
Indented = true
};
using (var stream = new MemoryStream())
{
using (var writer = new Utf8JsonWriter(stream, options))
{
writer.WriteStartObject();
writer.WriteString("date", DateTimeOffset.UtcNow);
writer.WriteNumber("temp", 42);
writer.WriteEndObject();
}
string json = Encoding.UTF8.GetString(stream.ToArray());
Console.WriteLine(json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment