transform ec2 tags with jq and node.js

87 views Asked by At

I need to transform this ec2 tags (array)

[ 
    { Key: 'Name', Value: 'xxx' },
    { Key: 'role', Value: 'yyy' } 
]

to

{ 
 name : 'xxx',
 role : 'yyy'
}

using jq and node.js. Could you help please regards

1

There are 1 answers

0
Guerric P On

You could use Object.fromEntries like this:

const tags = [ 
    { Key: 'Name', Value: 'xxx' },
    { Key: 'role', Value: 'yyy' } 
];


const obj = Object.fromEntries(tags.map(({ Key, Value }) => [Key, Value]));

console.log(obj);