title: Is there a way to return either a string or embedded JSON using FOR JSON?
body: <p>I have a nvarchar column that I would like to return embedded in my JSON results if the contents is valid JSON, or as a string otherwise.</p>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>select
    (
      case when IsJson(Arguments) = 1 then 
        Json_Query(Arguments) 
      else 
        Arguments 
      end
    ) Results
    from Unit
    for json path
  </code></pre>
  
  <p>This always puts Results into a string.</p>
  
  <p>The following works, but only if the attribute contains valid JSON:</p>
  
  <pre><code>select
      (
        Json_Query(
          case when IsJson(Arguments) = 1 then 
            Arguments 
          else 
            '"' + String_escape(IsNull(Arguments, ''), 'json') + '"' end
        )
      ) Results
      from Unit
      for json path
  </code></pre>
  
  <p>If Arguments does not contain a JSON object a runtime error occurs.</p>
  
  <p>Update: Sample data:</p>
  
  <pre><code>Arguments
  ---------
  { "a": "b" }
  Some text
  </code></pre>
  
  <p>Update: any version of SQL Server will do.  I'd even be happy to know that it's coming in a beta or something.</p>