title: Querying json key name in SQL Server
body: <p>Given json like this...</p>
  
  <pre><code>{"setting1":"A","setting2":"B","setting3":"C"}
  </code></pre>
  
  <p>I would like to see results like...</p>
  
  <pre><code>+----------+-------+
  |   name   | value |
  +----------+-------+
  | setting1 | A     |
  | setting2 | B     |
  | setting3 | C     |
  +----------+-------+
  </code></pre>
  
  <p>My struggle is I'm trying to find out how to extract the key's name (i.e., "setting1", "setting2", "setting3", etc.)</p>
  
  <p>I could do something like the following query, but I don't know how many settings there will be and what their names will be, so I'd like something more dynamic.</p>
  
  <pre><code>SELECT
      B.name,
      B.value
  FROM OPENJSON(@json) WITH
      (
          setting1 varchar(50) '$.setting1',
          setting2 varchar(50) '$.setting2',
          setting3 varchar(50) '$.setting3'
      ) A
  CROSS APPLY
      (
          VALUES
              ('setting1', A.setting1),
              ('setting2', A.setting2),
              ('setting3', A.setting3)
      ) B (name, value)
  </code></pre>
  
  <p>With XML, I could do something simple like this:</p>
  
  <pre><code>DECLARE @xml XML = '&lt;settings&gt;&lt;setting1&gt;A&lt;/setting1&gt;&lt;setting2&gt;B&lt;/setting2&gt;&lt;setting3&gt;C&lt;/setting3&gt;&lt;/settings&gt;'
  SELECT
      A.setting.value('local-name(.)', 'VARCHAR(50)') name,
      A.setting.value('.', 'VARCHAR(50)') value
  FROM @xml.nodes('settings/*') A (setting)
  </code></pre>
  
  <p>Any way to do something similar with SQL Server's json functionality?</p>