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.
I've gone through all of the JMESPath docs and examples without finding the specific data structure I've been working with. I've tried using the keys(@) and values(@) 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.
Here is my original JSON data
{
"time": 32,
"terms": {
"192.168.10.121": 84,
"154.223.10.121": 12,
"112.149.10.121": 6
}
}
I'm trying to convert the above JSON data to the following strucutre using JMESPath.
{
"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 }
]}
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.
terms.{ data: keys(@)}
terms.{ data: values(@)}
Result when using terms.{ data: keys(@)}
{
"data": [
"192.168.10.121",
"154.223.10.121",
"112.149.10.121"
]}
Result when using terms.{ data: values(@)}
{
"data": [
84,
12,
6
]}
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.
I'm not even sure this is possible using JMESPath. Any expert opinion would be greatly appreciated.