title: How to take key value pairs and turn them into an array of objects using JMESPath
body: <p>I'm looking to change the data structure of a 3rd party API using JMESPath and haven't been able to figure out how to take a single object of key-value pairs and restructure this to an array of objects, each containing key-value pairs.</p>
  
  <p>I've gone through all of the <a href="http://jmespath.org/specification.html" rel="nofollow noreferrer" title="JMESPath Specification">JMESPath docs</a> and <a href="http://jmespath.org/examples.html" rel="nofollow noreferrer" title="JMESPath Examples">examples</a> without finding the specific data structure I've been working with. I've tried using the <a href="http://jmespath.org/specification.html#keys" rel="nofollow noreferrer" title="JMESPath Keys Function">keys(@)</a> and <a href="http://jmespath.org/specification.html#values" rel="nofollow noreferrer" title="JMESPath Values Function">values(@)</a> built-in functions to grab the key and values of these pairs, but haven't been able to join them together into a single array.</p>
  
  <p>Here is my original JSON data</p>
  
  <pre><code>{
  "time": 32,
      "terms": {
          "192.168.10.121": 84,
          "154.223.10.121": 12,
          "112.149.10.121": 6
      }
  }
  </code></pre>
  
  <p>I'm trying to convert the above JSON data to the following strucutre using JMESPath.</p>
  
  <pre><code>{
  "data": [
      { "ip_address": "192.168.10.121", "count": 84 },
      { "ip_address": "154.223.10.121", "count": 12 },
      { "ip_address": "112.149.10.121", "count": 6 }
  ]}
  </code></pre>
  
  <p>I've been able to create an array of the keys or an array of values, but not able to create the array of objects containing key-value pairs.
  <code>terms.{ data: keys(@)}</code>
  <code>terms.{ data: values(@)}</code></p>
  
  <p>Result when using <code>terms.{ data: keys(@)}</code></p>
  
  <pre><code>{
  "data": [
      "192.168.10.121",
      "154.223.10.121",
      "112.149.10.121"
  ]}
  </code></pre>
  
  <p>Result when using <code>terms.{ data: values(@)}</code></p>
  
  <pre><code>{
  "data": [
      84,
      12,
      6
  ]}
  </code></pre>
  
  <p>Those two functions seem like the only functions I can use to pull the keys and values from an object containing key-value pairs not originally within an array. From what I can tell, I'm not able to combine both of those functions to output a single array like my example above.</p>
  
  <p>I'm not even sure this is possible using JMESPath. Any expert opinion would be greatly appreciated.</p>