title: Creating JSON objects from JSON object properties in MySQL query
body: <p>I need to create a list of JSON objects from properties in JSON object using MySQL 5.7. I have this structure:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;X&quot;: 1,
      &quot;Y&quot;: 1,
      &quot;Z&quot;: 55,
      &quot;A&quot;: 2,
      &quot;B&quot;: 33
  }
  </code></pre>
  <p>I want to have the properties to be separated as objects and sorted by the keys in those objects like this:</p>
  <pre class="lang-json prettyprint-override"><code>[
      {&quot;A&quot;: 2},
      {&quot;B&quot;: 3},
      {&quot;X&quot;: 1},
      {&quot;Y&quot;: 1},
      {&quot;Z&quot;: 55}
  ]
  </code></pre>
  <p>I tried to separate keys and values and maybe then somehow merge it</p>
  <pre><code>TRIM(LEADING '[' FROM TRIM(TRAILING ']' FROM JSON_KEYS(letters_and_values)))           as letters,
  TRIM(LEADING '[' FROM TRIM(TRAILING ']' FROM JSON_EXTRACT(letters_and_values, '$.*'))) as values,
  </code></pre>
  <p>But I feel I'm complicating it. Does anyone know the easiest way to achieve the expected result?</p>