title: Using new Json serializer with HttpContext.Response in ASP.NET Core 3.1
body: <p>When we want to serialize an object to a JSON string in ASP.NET Core's pipeline, we need to work with <code>HttpContext.Response.Body.WriteAsync</code>, unless I'm missing something, as there's no <code>Result</code> property which we can easily use to assign a <code>JsonResult</code> object to.</p>
  
  <p>Unless there's a better alternative, how exactly is serialization achieved by using the above method?</p>
  
  <p><strong>Note:</strong> The options for the JSON serializer should be the same as the (default) ones being used in ASP.NET Core 3.1.</p>
  
  <p><em>If desired (not in our case), they can be modified via the <code>IServiceCollection.AddJsonOptions</code> middleware.</em></p>
  
  <p>Example:</p>
  
  <pre><code>app.Use( next =&gt;
  {
      return async context =&gt;
      {
          if (&lt;someFunkyConditionalExample&gt;)
          {
              // serialize a JSON object as the response's content, returned to the end-user.
              // this should use ASP.NET Core 3.1's defaults for JSON Serialization.
          }
          else
          {
              await next(context);
          }
      };
  });
  </code></pre>