title: SQL to JSON - array of objects to array of values with UNION ALL
body: <p>How to make the query below work?</p>
  
  <p>I used the concept from another question <a href="https://stackoverflow.com/a/39948323/2057854">SQL Server 2016 JSON: Select array of strings instead of array of objects</a></p>
  
  <p>But when I tried the select below it doesn't work</p>
  
  <pre><code>SELECT
      (SELECT line AS "line"  
       FROM
           (SELECT 
                CONCAT('5th', ' ', '566') AS "line"
            UNION ALL
            SELECT 'Complement' AS LINE
           )
       FOR JSON PATH) AS "address.lines"
  </code></pre>
  
  <p>The version of the SQL Server <code>SELECT @@VERSION</code> = <code>Microsoft SQL Server 2016</code></p>
  
  <p>The result from the query is</p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Line 11<br>
    Incorrect syntax near the keyword 'FOR'.</p>
  </blockquote>
  
  <p>The excepted result is <code>[{"line":"5th 566"},{"line":"Complement"}]</code>, with this result I will use the function from <a href="https://stackoverflow.com/a/39948323/2057854">SQL Server 2016 JSON: Select array of strings instead of array of objects</a> to remove "line" and get the final result <code>["5th 566","Complement"]</code></p>
  
  <p>I need to use the <code>UNION ALL</code> because I have two different values from the same table to result in an array called <code>address.lines</code> at the JSON result</p>