title: Converting simple value to JSON in ASP.NET Core API
body: <p>Sometimes my ASP.NET Core API needs to return a simple value i.e. <code>bool</code>, <code>int</code> or <code>string</code> even though in most cases, I return complex objects/arrays as <code>JSON</code>.</p>
  
  <p>I think for consistency purposes, it's a good idea to return even simple values as <code>JSON</code>. What's the easiest way to convert a simple value, whether it's <code>bool</code> or <code>int</code> into <code>JSON</code>?</p>
  
  <p>My standard controller action looks like this -- see below -- which gives me the ability to return status codes as well as data. Therefore, I'd like to stick to that approach, rather than return <code>JsonResult</code>.</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; Get()
  {
     // Some logic
     return Ok(data);
  }
  </code></pre>
  
  <p>I'm just trying to figure out the easiest way to convert my <code>data</code> into <code>JSON</code>, if it's not already in <code>JSON</code> format.</p>