I'm trying to create a web populated parameter for Teamcity Is there exist a way to perform such transformation in one jolt-specification without external logic?
Input:
{
"version": "1",
"servers": {
"dev1": {
"name": "dev1",
"addr": "http://server1:443"
},
"dev2": {
"name": "dev2",
"addr": "http://server2:443"
},
"dev3": {
"name": "dev3",
"addr": "http://server3:443"
},
"dev4": {
"name": "dev4",
"addr": "http://server4:443"
}
}
}
Expected output:
{
"options" : [ {
"value" : "dev1",
"enabled" : "true",
"key" : "dev1"
}, {
"value" : "dev2",
"enabled" : "true",
"key" : "dev2"
}, {
"value" : "dev3",
"enabled" : "true",
"key" : "dev3"
}, {
"value" : "dev4",
"enabled" : "true",
"key" : "dev4"
} ]
}
My specification with wrong output:
[
{
"operation": "shift",
"spec": {
"servers": {
"*": {
"$0": "options.[].value",
"name": "options.[].key",
"#true": "options.[].enabled"
}
}
}
}
]
CodePudding user response:
All desired key-value pairs should be accumulated under common nodes which should be the sub-indexes of the servers objects in my opinion such that
[
{
"operation": "shift",
"spec": {
"servers": {
"*": {
"$": "&1.value",
"name": "&1.key",
"#true": "&1.enabled"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": "options"
}
}
]
in the current case ( options.[]
which's equal to options[]
) have no indexes nested within square bracket notations.
CodePudding user response:
Found the answer with one step transformation via shift by an example from here
[
{
"operation": "shift",
"spec": {
"servers": {
"*": {
"$": "options[#2].value",
"name": "options[#2].key",
"#true": "options[#2].enabled"
}
}
}
}
]