title: SQL Server For JSON Path dynamic column name
body: <p>We are exploring the <code>JSON feature in SQL Sever</code> and for one of the scenarios we want to come up with a SQL which can return a JSON like below</p>
  
  <pre><code>[
    {
      "field": {
        "uuid": "uuid-field-1"
      },
      "value": {
        "uuid": "uuid-value" //value is an object
      }
    },
    {
      "field": {
        "uuid": "uuid-field-2"
      },
      "value": "1". //value is simple integer
    }
    ... more rows
  ]
  </code></pre>
  
  <p>The <code>value</code> field can be a simple integer/string or a nested object.</p>
  
  <p>We are able to come up with a table which looks like below:</p>
  
  <pre><code>field.uuid  | value.uuid | value|
  ------------|----------  | -----|
  uuid-field-1| value-uuid | null |
  uuid-field-2| null       | 1    |
    ... more rows
  </code></pre>
  
  <p>But as soon as we apply <code>for json path</code>, it fails saying </p>
  
  <blockquote>
    <p>Property 'value' cannot be generated in JSON output due to a conflict with another column name or alias. Use different names and aliases for each column in SELECT list.</p>
  </blockquote>
  
  <p>Is it possible to do it somehow generate this? The value will either be in the <code>value.uuid</code> or <code>value</code> not both?</p>
  
  <p><strong>Note:</strong> We are open to possibility of if we can convert each row to individual JSON and add all of them in an array.</p>