Follow up question to JOLT spec - Is it possible to sort values according key/value of a list of dict?
What about adding more option :
JSON Input :
{
"list": [
{
"tags": [
{
"scope": "",
"tag": "TAG_VM"
},
{
"scope": "",
"tag": "TAG_HOST"
},
{
"scope": "",
"tag": "TAG_ROLE_DNS"
},
{
"scope": "",
"tag": "TAG_ROLE_AD"
},
{
"scope": "",
"tag": "TAG_USER_INSIDE"
},
{
"scope": "",
"tag": "TAG_USER_OUTSIDE"
},{
"scope": "",
"tag": "TAG_INTERNET_TRUE"
}
]
}
],
"result_count": 1,
"sort_by": "name"
}
Disered Ouput:
{
"role1" : "DNS",
"role2" : "AD",
"user1" : "INSIDE",
"user2" : "OUTSIDE",
"internet" : "TRUE"
}
Thanks for helping !
CodePudding user response:
The similar logic will work along with building and using multiple independent arrays by making it more dynamic this case such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"*": {
"*": {
"TAG_*_*": {
"$": "&(1,1).&(1,2)"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&2"
},
"#0": "&1"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"@": "&2&"
}
}
}
},
{
"operation": "remove",
"spec": {
"*0": ""
}
},
{ // exchange key-value pairs to be able to convert keys to lower case
"operation": "shift",
"spec": {
"*": {
"$": "@(0)"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=toLower(@(1,&))"
}
},
{ // exchange key-value pairs back to the original
"operation": "shift",
"spec": {
"*": {
"$": "@(0)"
}
}
}
]